#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <iomanip>
#include <functional>
#include <complex>
#include <array>

using namespace std;
template<class T,class U>inline constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>inline constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
using pii=pair<int,int>;
using ll=long long int;
constexpr int MAX=(1<<30)-1;
constexpr int inf=(1LL<<50);
int dx[]={0,1,-1,0},dy[]={1,0,0,-1}; //→↓↑←

//要素数n 初期値x
template<typename T>
inline vector<T> vmake(size_t n,T x){
  return vector<T>(n,x);
}

//a,b,c,x data[a][b][c] 初期値x
template<typename... Args>
auto vmake(size_t n,Args... args){
    auto v=vmake(args...);
    return vector<decltype(v)>(n,move(v));
}

vector<string> C;
int height,width;
vector<vector<bool>> C_used; //trueなら確実に餌がない falseならまだ分からない
vector<vector<ll>> C_prob;
vector<vector<ll>> C_Point;

set<pii> set_Pellet;
set<pii> set_Super;

vector<vector<vector<vector<int>>>> Distance; //[sh][sw][th][tw] sh,sw→th,twの距離
vector<vector<vector<vector<pii>>>> connect_Distance; //[sh][sw][distance] sh,swから距離distanceにあるグリッド

//じゃんけん
map<string,int> to_number;
map<int,string> to_mozi;

//pacID,typeID,hight,width,speedleft,cooldown
vector<array<int,6>> MINE,ENEMY;

//pacID,hight,width,do_type,maru
vector<array<int,4>> ACTIVE;
vector<array<int,4>> lastACTIVE;

int find_distance(array<int,6> &x,pii y){
    return Distance[x[2]][x[3]][y.first][y.second];
}
int find_distance(array<int,6> &x,array<int,6> &y){
    return Distance[x[2]][x[3]][y[2]][y[3]];
}
int find_distance(pii x,pii y){
    return Distance[x.first][x.second][y.first][y.second];
}
int find_distance(int sh,int sw,int th,int tw){
    return find_distance(pii(sh,sw),pii(th,tw));
}


vector<vector<int>> make_distance(int sh,int sw){
    auto dist=vmake(height,width,MAX);
    queue<pii> que;
    que.emplace(sh,sw);
    dist[sh][sw]=0;
    while(!que.empty()){
        int h,w;
        tie(h,w)=que.front(); que.pop();
        for(int i=0;i<4;i++){
            int nh=h+dx[i],nw=w+dy[i];
            nh=(nh+height)%height;nw=(nw+width)%width;
            if(C[nh][nw]=='#') continue;
            if(dist[nh][nw]>dist[h][w]+1){
                dist[nh][nw]=dist[h][w]+1;
                que.emplace(nh,nw);
            }
        }
    }
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            if(dist[i][j]==MAX) continue;
            connect_Distance[sh][sw][dist[i][j]].push_back(pii(i,j));
        }
    }
    return dist;
}

void kakutei_Beam(){
    for(int i=0;i<MINE.size();i++){
        int h,w;
        h=MINE[i][2];
        w=MINE[i][3];
        for(int th=0;th<height;th++){
            if(find_distance(pii(h,w),pii(th,w))==abs(th-h) and (set_Pellet.find(pii(th,w))==set_Pellet.end() and set_Super.find(pii(th,w))==set_Super.end()) ){
                C[th][w]=true;
            }
        }
        for(int tw=0;tw<width;tw++){
            if(find_distance(pii(h,w),pii(h,tw))==abs(tw-w) and (set_Pellet.find(pii(h,tw))==set_Pellet.end() and set_Super.find(pii(h,tw))==set_Super.end()) ){
                C[h][tw]=true;
            }
        }
    }
}

ll ans_sum;


void Turn_init(){
    MINE.clear();
    ENEMY.clear();
    set_Pellet.clear();
    ans_sum=-inf;
}



void Game_init(){
    to_mozi[0]="ROCK";
    to_mozi[1]="PAPER";
    to_mozi[2]="SCISSORS";
    to_mozi[3]="ROCK";
    to_number["ROCK"]=0;
    to_number["PAPER"]=1;
    to_number["SCISSORS"]=2;

    cin >> width >> height; cin.ignore();
    C.resize(height);
    C_used=vmake(height,width,false);
    connect_Distance=vmake(height,width,500,vector<pii>());
    for (int i = 0; i < height; i++) {
        string row;
        getline(cin,row);
        C[i]=row;
    }
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            if(C[i][j]=='#') C_used[i][j]=true;
        }
    }
    Distance=vmake(height,width,height,width,0); 
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            if(C[i][j]=='#') continue;
            Distance[i][j]=make_distance(i,j);
        }
    }

    C_prob=vmake(height,width,0LL);
    C_Point=vmake(height,width,0LL);
}


void set_grid_Point(){
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            if(C_used[i][j]) C_prob[i][j]=0;
            else if(set_Super.find(pii(i,j))!=set_Super.end()){
                    C_prob[i][j]=2000000; //2e6

            }else if(set_Pellet.find(pii(i,j))!=set_Pellet.end()){
                C_prob[i][j]=1000; //1e3
            }else if(C_prob[i][j]>1000){
                C_prob[i][j]=0;
                C_used[i][j]=true;
            }else{
                C_prob[i][j]-=20;
                chmax(C_prob[i][j],100); //完全に不明100
            }
        }
    }
    //全方位木みたいにする必要がありそうだけど簡略化する
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            C_Point[i][j]=0;
            for(int d=0;d<=13;d++){
                for(auto x:connect_Distance[i][j][d]){
                    int p;
                    if(d==0) p=100;
                    else p=14-d;
                    C_Point[i][j]+=C_prob[x.first][x.second]*p;
                }
            }
        }
    }
}

//距離0を選ばせないようにする -inf
ll mine_distance_Point(){
    int sum_Point=0;
    for(int i=0;i<MINE.size();i++){
        for(int j=i+1;j<MINE.size();j++){
            int dist=find_distance(ACTIVE[i][1],ACTIVE[i][2],ACTIVE[j][1],ACTIVE[j][2]);
            if(dist==0) sum_Point-=inf;
            else if(dist==1) sum_Point-=3000000000;
            else if(dist==2) sum_Point-=2000000000;
            else sum_Point-=2000-dist*50;
        }
    }
    return sum_Point;
}


void active_simulate(int idx,ll tmp_Point){
    if(idx==MINE.size()){
        ll x=mine_distance_Point();
        if(chmax(ans_sum,tmp_Point+x)){
            cerr<<"AAAA"<<endl;
            lastACTIVE=ACTIVE;
        }
        return;
    }
    for(int i=0;i<4;i++){
        int nh,nw;
        if(i<4) nh=(MINE[idx][2]+height+dx[i])%height,nw=(MINE[idx][3]+width+dy[i])%width;
        else nh=MINE[idx][2],nw=MINE[idx][3];
        ACTIVE[idx][0]=MINE[idx][0];
        ACTIVE[idx][1]=nh; ACTIVE[idx][2]=nw;
        ACTIVE[idx][3]=0;
        if(C[nh][nw]=='#') continue;
        cerr<<C_Point[nh][nw]<<endl;
        active_simulate(idx+1,tmp_Point+C_Point[nh][nw]);
    }
}

void PRINT(){
    for(int i=0;i<ACTIVE.size();i++){
        if(lastACTIVE[i][3]==0){
            cout<<"|MOVE "<<lastACTIVE[i][0]<<" "<<lastACTIVE[i][2]<<" "<<lastACTIVE[i][1];
        }
    }
}

int main()
{
    Game_init();

    // game loop
    while (1) {
        Turn_init();
        int myScore;
        int opponentScore;
        cin >> myScore >> opponentScore; cin.ignore();
        cerr<<myScore<<" "<<opponentScore<<endl;
        int visiblePacCount; // all your pacs and enemy pacs in sight
        cin >> visiblePacCount; cin.ignore();
        for (int i = 0; i < visiblePacCount; i++) {
            cerr<<i<<endl;
            int pacId; // pac number (unique within a team)
            bool mine; // true if this pac is yours
            int x; // position in the grid
            int y; // position in the grid
            string typeId; // unused in wood leagues
            int speedTurnsLeft; // unused in wood leagues
            int abilityCooldown; // unused in wood leagues
            cin >> pacId >> mine >> x >> y >> typeId >> speedTurnsLeft >> abilityCooldown; cin.ignore();
            if(mine){
                MINE.push_back({pacId,to_number[typeId],y,x,speedTurnsLeft,abilityCooldown});
            }else{
                ENEMY.push_back({pacId,to_number[typeId],y,x,speedTurnsLeft,abilityCooldown});
            }
            C_used[y][x]=true;
        }
        ACTIVE.resize(MINE.size());
        int visiblePelletCount; // all pellets in sight
        cin >> visiblePelletCount; cin.ignore();
        for (int i = 0; i < visiblePelletCount; i++) {
            int x;
            int y;
            int value; // amount of points this pellet is worth
            cin >> x >> y >> value; cin.ignore();
            if(value==10){
                set_Super.insert(pii(y,x));
            }else{
                set_Pellet.insert(pii(y,x));
            }
        }
        cerr<<MINE.size()<<endl;
        kakutei_Beam();
        cerr<<MINE.size()<<endl;
        set_grid_Point();
        cerr<<MINE.size()<<endl;
        active_simulate(0,0);
        cerr<<"aaa"<<endl;
        PRINT();
        // Write an action using cout. DON'T FORGET THE "<< endl"
        // To debug: cerr << "Debug messages..." << endl;

        cout<<endl;
    }
}