#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int, int>;

//editorial

int main(){
    int n;
    string s, x;
    cin >> n >> s >> x;
    
    vi dp(n+1, 0);
    dp[n] = 1;//dp[n] = {0};
    for(int i=n-1; i>=0; i--){
        if(x[i]=='T'){
            rep(r, 7){
                if( ( 1<<(10*r%7) )&dp[i+1] )dp[i] |= 1<<r;
                if( ( 1<<((10*r + s[i]-'0')%7) )&dp[i+1] )dp[i] |= 1<<r;
            }
        }
        else{
            rep(r, 7){
                if( ( 1<<(10*r%7) )&dp[i+1] && ( 1<<((10*r + s[i]-'0')%7) )&dp[i+1] )dp[i] |= 1<<r;
            }
        }
    }
    cout << (dp[0]&1?"Takahashi":"Aoki") << endl;
    return 0;
}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MOD=998244353;
ll modpow(ll x,ll n){
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  return ans;
}

ll G[5050][5050];
ll T[5050][5050];

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  
  vector<vector<char>> A(h+1,vector<char> (w+1,'Z'));
  vector<ll> C(h+w+2);
  int p=min(h,w);
  rep(i,h+w) C[i]=min({i+1,p,h+w-i-1});
  
  rep(i,k){
    int y,x;
    char c;
    cin>>y>>x>>c;
    y--,x--;
    C[x+y]--;
    A[y][x]=c;
  }
  
  rep(i,h){
    rep(j,w){
      if(A[i][j]!='Z'){
        T[i][j]=modpow(3,C[i+j]);
      }
      else{
        T[i][j]=modpow(3,C[i+j]-1);
      }
    }
  }
  
  G[0][0]=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(A[i][j]=='X'){
        G[i+1][j]=(G[i+1][j]+G[i][j]*T[i+1][j]%MOD)%MOD;
        G[i][j+1]=(G[i][j+1]+G[i][j]*T[i][j+1]%MOD)%MOD;
      }
      else if(A[i][j]=='R'){
        G[i][j+1]=(G[i][j+1]+G[i][j]*T[i][j+1]%MOD)%MOD;
      }
      else if(A[i][j]=='D'){
        G[i+1][j]=(G[i+1][j]+G[i][j]*T[i+1][j]%MOD)%MOD;
      }
      else{
        G[i+1][j]=(G[i+1][j]+G[i][j]*2%MOD*T[i+1][j]%MOD)%MOD;
        G[i][j+1]=(G[i][j+1]+G[i][j]*2%MOD*T[i][j+1]%MOD)%MOD;
      }
    }
  }
  
  if(A[h-1][w-1]!='Z') cout<<G[h-1][w-1]<<endl;
  else cout<<G[h-1][w-1]*3%MOD<<endl;

  return 0;
}