#include <iostream>
#include <string>

using namespace std;
string krvna_grupa;
int main()
{
    int n;
    cin>>n;
    int bro=0, bra=0, brb=0, brab=0, ao, aob, aoab;

    int o,a,b,ab;
    cin>>o>>a>>b>>ab;

    for(int i=0; i<n; i++){
        int br;
        cin>>krvna_grupa>>br;
        if(krvna_grupa=="O")bro=br;
        if(krvna_grupa=="A")bra=bro+br;
        if(krvna_grupa=="B")brb=br+bro;
        if(krvna_grupa=="AB")brab=bra+brb-bro+br;
    }

    if(o<bro){
    	cout<<"nemoguce"<<'\n';
    	return 0;
	}else{
		o=o-bro;
		bra=bra-bro;
	}
	
	if((a+o)<bra){
		cout<<"nemoguce"<<'\n';
		return 0;
	}else{
		ao=(a+o);
		ao=ao-bra;
		brb=brb-ao;
	}
	
	if((b+o+a)<brb){
		cout<<"nemoguce"<<'\n';
		return 0;
	}else{
		aob=(a+o+b);
		aob=aob-brb;
		brab=brab-aob;
	}
	
	if((a+o+b+ab)<brab){
		cout<<"nemoguce"<<'\n';
		return 0;
	}else{
	     aoab=(a+o+b+ab);
	     aoab=aoab-brab;
	}
	cout<<"moguce"<<endl;

    return 0;
}