#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
int o,a,b,ab;
cin>>n;
cin>>o>>a>>b>>ab;
int ot=0,at=0,bt=0,abt=0;
vector<pair<string, int> > v;
for(int i=0;i<n;i++)
{
string s;
int t;
cin>>s>>t;
v.push_back(make_pair(s,t));
if(s=="O")
ot+=t;
else if(s=="A")
at+=t;
else if(s=="B")
bt+=t;
else
abt+=t;
}
int ostaloo,ostaloa,ostalob;
if(o<ot)
{
cout<<"nemoguce"<<endl;
return 0;
}
else
ostaloo=o-ot;
if(a+ostaloo<at)
{
cout<<"nemoguce"<<endl;
return 0;
}
else
{
if(a>=at)
ostaloa=a-at;
else
{
ostaloa=0;
ostaloo=(ostaloo)-(at-a);
}
}
if(b+ostaloo<bt)
{
cout<<"nemoguce"<<endl;
return 0;
}
else
{
if(b>=bt)
ostalob=b-bt;
else
{
ostalob=0;
ostaloo=(ostaloo)-(bt-b);
}
}
if(ostaloo+ostaloa+ostalob+ab<abt)
{
cout<<"nemoguce"<<endl;
return 0;
}
map<int, vector<int> > resenja;
cout<<"moguce"<<endl;
for(int i=0;i<n;i++)
{
if(v[i].first=="O")
{
resenja[i].push_back(v[i].second);
resenja[i].push_back(0);
resenja[i].push_back(0);
resenja[i].push_back(0);
o-=v[i].second;
}
else if(v[i].first=="A")
{
if(a>=v[i].second)
{
resenja[i].push_back(0);
resenja[i].push_back(v[i].second);
resenja[i].push_back(0);
resenja[i].push_back(0);
a-=v[i].second;
}
else
{
v[i].second-=a;
resenja[i].push_back(v[i].second);
resenja[i].push_back(a);
resenja[i].push_back(0);
resenja[i].push_back(0);
a=0;
o-=v[i].second;
}
}
else if(v[i].first=="B")
{
if(b>=v[i].second)
{
resenja[i].push_back(0);
resenja[i].push_back(0);
resenja[i].push_back(v[i].second);
resenja[i].push_back(0);
b-=v[i].second;
}
else
{
v[i].second-=b;
resenja[i].push_back(v[i].second);
resenja[i].push_back(0);
resenja[i].push_back(b);
resenja[i].push_back(0);
b=0;
o-=v[i].second;
}
}
}
for(int i=0;i<n;i++)
{
if(v[i].first=="AB")
{
if(o>=v[i].second)
{
resenja[i].push_back(v[i].second);
resenja[i].push_back(0);
resenja[i].push_back(0);
resenja[i].push_back(0);
o-=v[i].second;
}
else
{
resenja[i].push_back(o);
v[i].second-=o;
o=0;
if(a>=v[i].second)
{
resenja[i].push_back(v[i].second);
resenja[i].push_back(0);
resenja[i].push_back(0);
a-=v[i].second;
}
else
{
resenja[i].push_back(a);
v[i].second-=a;
a=0;
if(b>=v[i].second)
{
resenja[i].push_back(v[i].second);
resenja[i].push_back(0);
b-=v[i].second;
}
else
{
resenja[i].push_back(b);
v[i].second-=b;
b=0;
resenja[i].push_back(v[i].second);
ab-=v[i].second;
}
}
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<4;j++)
cout<<resenja[i][j]<<" ";
cout<<endl;
}
return 0;
}