#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10010][5];
int n;
map<string,int>m;
map<string,int>ind;
pair<string,int>pp[10010];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ind["O"]=0;
    ind["A"]=1;
    ind["B"]=2;
    ind["AB"]=3;
    cin >> n;
    cin >> m["O"] >> m["A"] >> m["B"] >> m["AB"];
    for (int i=0; i<n; i++)
    {
        string s;
        cin >> s;
        int p;
        cin >> p;
        pp[i]=make_pair(s,p);
    }
    cout << "nemoguce";
    return 0;
}