#include <iostream>

using namespace std;

int main()
{
    int N,o,a,b,ab,x,y,z,t;
    int jedinica[N];
    string krvnagrupa[N],O,A,B,AB;
    cin>>N;
    cin>>o>>a>>b>>ab;
    x=0;
    y=0;
    z=0;
    t=0;

    for(int i=1;i<=N;i++)
        {

            cin>>krvnagrupa[i]>>jedinica[i];
            if (krvnagrupa[i]=="O")
                x=x+jedinica[i];
            if (krvnagrupa[i]=="A")
                y=y+jedinica[i];
            if (krvnagrupa[i]=="B")
                z=z+jedinica[i];
            if (krvnagrupa[i]=="AB")
                t=t+jedinica[i];
        }
    if(x>o)
        cout<<"nemoguce"<<endl;
    else{
        if(y>a+(o-x))
            cout<<"nemoguce"<<endl;
        else{
            if(z>b+(o-x-y+a))
                cout<<"nemoguce"<<endl;
            else{
                if(t>ab+(o-x-y+a-z+b))
                    cout<<"nemoguce"<<endl;
                else
                    cout<<"moguce"<<endl;