#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

/* // Ordered Set
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
template<typename T>
typedef tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)
*/

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define cntleadz(x) __builtin_clz(x) // or add ll at the end for long long
#define cnttrailz(x) __builtin_ctx(x)
#define cntpop(x) __builtin_popcount(x)
#define binparity(x) __builtin_parity(x)
#define pb push_back
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
// #define mod 1000000007
#define mod 998244353
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

ll binExp(ll x,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

// ll fact[200001];
// ll ncr(int n,int r) {return (n>=r?(fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod:0);}
ll modInv(ll i) {return binExp(i,mod-2);}
ll add(ll a, ll b) {ll res = a+b; if(res >= mod) res -= mod; return res;}
ll mul(ll a, ll b) {ll res = a*b; res %= mod; return res;}

char mat[5001][5001];
int dp[5001][5001];

void solve()
{
    int h,w,k;
    cin>>h>>w>>k;

    f1(i,1,h) f1(j,1,h) {mat[i][j] = '.';dp[i][j] = 0;}
    
    dp[1][1] = binExp(3,h*w-k);;

    int a,b;
    char c;
    f0(_,0,k)
    {
        cin>>a>>b>>c;

        mat[a][b] = c;
    }

    int by3 = modInv(3);

    f1(i,1,h) f1(j,1,w)
    {
        if(i!=1 && mat[i-1][j] != 'R')
        {
            if(mat[i-1][j] == 'X' || mat[i-1][j] == 'D')
                dp[i][j] = add(dp[i][j], dp[i-1][j]);
            else
                dp[i][j] = add(dp[i][j], mul(2*dp[i-1][j], by3));
        }
        if(j!=1 && mat[i][j-1] != 'D')
        {
            if(mat[i][j-1] == 'X' || mat[i][j-1] == 'R')
                dp[i][j] = add(dp[i][j], dp[i][j-1]);
            else
                dp[i][j] = add(dp[i][j], mul(2*dp[i][j-1], by3));
        }
        // if(i==2&&j==1)
        // {
        //     cout<<dp[i][j]<<"----\n";
        // }
    }

    // f1(i,1,h)
    // {
    //     f1(j,1,w) cout<<mat[i][j]<<' '; cout<<'\n';
    // }

    // f1(i,1,h)
    // {
    //     f1(j,1,w) cout<<dp[i][j]<<' '; cout<<'\n';
    // }

    cout<<dp[h][w];
}

signed main()
{
    fast

    // clock_t start,end;
    #ifndef ONLINE_JUDGE
        freopen("inputf.txt","r",stdin);
        freopen("outputf.txt","w",stdout);
    #endif
    // start = clock();

    // fact[0] = 1;
    // f1(i,1,200000) fact[i] = mul(fact[i-1], i);

    // test
    solve();

    // end = clock();
    // double time_taken = double(end-start) / double(CLOCKS_PER_SEC);
    // cout<<time_taken<<" sec";
}
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;
const int INF = 1e9;
const long long INFLL = 1e18;
using ll = long long;

char RSP(char i, char j){
  if(i == 'S' && j == 'P') return 'S';
  if(i == 'R' && j == 'S') return 'R';
  if(i == 'P' && j == 'R') return 'P';
  if(i == 'S' && j == 'R') return 'R';
  if(i == 'R' && j == 'P') return 'P';
  if(i == 'P' && j == 'S') return 'S';
  
  return i;

}

int main(){
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  if(n % 2 == 1){
    n *= 2;
    for(int i = 0; i < n/2; i++) s.push_back(s[i]);
  }

  for(int i = 0; i < k; i++){
    string ss = "";
    for(int j = 0; j < n/2; j++){
      ss.push_back(RSP(s[2*j], s[2*j+1]));
    }
    for(int j = n/2; j < n; j++) ss.push_back(ss[j-n/2]);
    
    for(int j = 0; j < n; j++) s[j] = ss[j];
    // cout << s << endl;
  }

  cout << s[0] << endl;


  return 0;
}