#include<bits/stdc++.h>
using namespace std;
int hp,mhp,st,de,mst,mde;
char mp[101][101];
int maxhp;
int x,y;
int n,m,q;
void move(int x,int y,int d);
void check(int x,int y);
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>mp[i][j];
cin>>mhp>>mst>>mde;
cin>>x>>y;
cin>>hp>>st>>de;maxhp=hp;
cin>>q;
while(q--)
{
int op;
cin>>op;
if(op&1)
{
printf("%d %d %d\n",hp,st,de);
}
else if(!(op&1))
{
int d;
cin>>d;
move(x,y,d);
}
}
return 0;
}
void move(int x,int y,int d)
{
if(d==1) y--;
if(d==2) y++;
if(d==3) x--;
else x++;
check(x,y);
}
void check(int x,int y)
{
if(mp[x][y]=='R') hp=min(maxhp,hp+10);
else if(mp[x][y]=='Q') st+=5;
else if(mp[x][y]=='Y') de+=5;
else if(mp[x][y]=='M')
{
hp-=(int)max((double)1,ceil((double)max(1,st-mde)/(double)mhp)*max(1,mst-de));
}
}