#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long NumberofVarels;
    long long NumberofVarels2;
    long long kolkovzemat=0;
    char WhatTipeofVarels;
    char WhatTipeofVarels2;
    cin>>NumberofVarels;
    cin>>WhatTipeofVarels;
    cin>>NumberofVarels2;
    cin>>WhatTipeofVarels2;;
    cin>>kolkovzemat;
    if(WhatTipeofVarels=='A')
    {
        if(kolkovzemat<=NumberofVarels)
        {
            cout<<kolkovzemat<<" "<<"A";
        }
    }
    if(WhatTipeofVarels2=='B')
    {
        if(kolkovzemat<=NumberofVarels2)
        {
            cout<<kolkovzemat<<" "<<"B";
        }
    }
    return 0;
}
