#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m, q, x, y, xl, stp, dep, hpg, stg, deg;
char c[105][105];
signed main(){
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> c[i][j];
}
}
cin >> hpg >> stg >> deg;
cin >> x >> y;
cin >> stp >> dep;
cin >> q;
while(q--){
int op;
cin >> op;
if(op == 1){
cout << xl << " " << stp << " " << dep << "\n";
}
else{
int d;
cin >> d;
if(d == 1){
y--;
}
if(d == 2){
y++;
}
if(d == 3){
x--;
}
if(d == 4){
x++;
}
if(c[x][y] == 'R'){
xl -= 10;
xl = max(0ll, xl);
}
if(c[x][y] == 'Q'){
stp += 5;
}
if(c[x][y] == 'Y'){
dep += 5;
}
if(c[x][y] == 'M'){
int ans = 0;
ans = max(1ll, (long long)ceil(hpg / max(1ll, stp - deg))) * max(1ll, stg - dep);
xl += ans;
}
}
}
return 0;
}