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

using ll = long long;
#define all(x) x.begin(), x.end()

const ll M = 998244353;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	ll h, w; cin >> h >> w;
	vector<ll> p2(1005);
	p2[0] = 1;
	for(ll i = 1; i <= 1004; ++i) p2[i] = p2[i - 1] * 2 % M;
	vector<string> g(h);
	for(auto &v : g) cin >> v;
	ll dot_row = 0;
	vector<array<ll, 2>> pos;
	for(int i = 0; i < h; ++i)
		pos.push_back({i, 0});
	for(int i = 1; i < w; ++i)
		pos.push_back({h - 1, i}); 
	for(auto &[x, y] : pos){
		//cout << x << ' ' << y << '\n';
		ll red = 0, blue = 0;
		for(int i = 0; i <= min(x, w - 1 - y); ++i){
			if(g[x - i][y + i] == 'R')
				++red;
			else if(g[x - i][y + i] == 'B')
				++blue;
			//cout << "!!" << ' ' << x - i << ' ' << y + i << ' ' << g[x - i][y + i] << '\n';
		}
		if(red == 0 && blue == 0) ++dot_row;
		if(red && blue){
			cout << 0 << '\n';
			exit(0);
		}
	}
	//cout << dot_row << '\n';
	cout << p2[dot_row] % M << '\n';
}

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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }

void Solve()
{
	ll N;
	string S, X;
	cin >> N >> S >> X;
	reverse(ALL(S));
	reverse(ALL(X));

	VL amariRev(7);
	REP(i, 7) {
		amariRev[10 * i % 7] = i;
	}

	ll now;
	ll amari;
	ll prevIdx;
	static ll dp[(ll)2e5 + 5][7];

	dp[0][0] = 1;
	REP(i, N - 1) {
		ll matchVal = X[i] == 'T' ? 1 : 0;
		ll fillVal = X[i] == 'T' ? 0 : 1;
		fill(dp[i + 1], dp[i + 1] + 7, fillVal);
		REP(j, 7) {
			if (dp[i][j] == matchVal) {
				now = S[i] - '0';
				amari = (j - now + 14) % 7;
				prevIdx = amariRev[amari];
				dp[i + 1][prevIdx] = matchVal;
				now = 0;
				amari = (j - now + 14) % 7;
				prevIdx = amariRev[amari];
				dp[i + 1][prevIdx] = matchVal;
			}
		}
	}

	string ans;
	ll sVal = (S.back() - '0') % 7;
	if (X.back() == 'T') {
		ans = (dp[N - 1][0] || dp[N - 1][sVal]) ? "Takahashi" : "Aoki";
	} else {
		ans = (dp[N - 1][0] && dp[N - 1][sVal]) ? "Takahashi" : "Aoki";
	}

	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}
