#include<bits/stdc++.h>
using namespace std;
bool f[200001][7];
string s1,s2;
int n;
int main(){
	scanf("%d",&n);
	cin>>s1>>s2; 
	f[n][0]=1;
	for(int i=n-1;i>=0;i--){
		int num=s1[i]-'0';
		for(int j=0;j<7;j++)
			if(s2[i]=='A')
				f[i][j]=f[i+1][(j*10+num)%7]&f[i+1][(j*10)%7];
			else
				f[i][j]=f[i+1][(j*10+num)%7]|f[i+1][(j*10)%7];
	}
	if(f[0][0])printf("Takahashi");
	else printf("Aoki");
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 998244353;
const double pi = 2.0 * asin(1.0);
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a % mod * (a % mod) % mod;
        n >>= 1;
    }
    return res;
}
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<string> s(n);
    rep(i, n)
    {
        cin >> s[i];
    }
    vector<ll> d(n + m);
    vector<ll> d2(n + m);
    vector<ll> d3(n + m);
    rep(i, n)
    {
        rep(j, m)
        {
            if (s[i][j] == 'R')
            {
                d[i + j]++;
            }
            else if (s[i][j] == 'B')
            {
                d2[i + j]++;
            }
            else
            {
                d3[i + j]++;
            }
        }
    }
    ll co = 0;
    rep(i, n + m)
    {
        if (d[i] > 0 && d2[i] > 0)
        {
            cout << 0 << endl;
            return 0;
        }
        if (d3[i] > 0 && d[i] == 0 && d2[i] == 0)
        {
            co++;
        }
    }
    ll ans = modpow(2, co, MOD);
    cout << ans << endl;
}