/* Author: rrrr_wys
**/

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); ++ i)
#define per(i, a, b) for(int i = (a); i >= (b); -- i)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
typedef double db;
typedef long long ll;
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int N = 2000110;
const int mo = 1e9 + 7;

int n;
vector<pair<int,ll>> G[N];
ll f[N];
void dfs(int u, int pa) {
        for(auto &v: G[u]) if(v.fi != pa){
                f[v.fi] = f[u] ^ v.se;
                dfs(v.fi, u);
        }
}
ll a[N], A[2];
signed main () {
        ios::sync_with_stdio(false); cin.tie(0);
        cin >> n;
        rep(i,2,n) {
                int u, v; ll w;
                cin >> u >> v >> w;
                G[u].pb({v,w}); G[v].pb({u,w});
        }
        dfs(1,0);
        ll ans =0;
        rep(ti,0,60) {
                rep(i,1,n) a[i] = !!(f[i]&(1ll<<ti));
                ll tt = 0;
                rep(i,1,n) {
                        if(a[i] == 0) tt += A[1];
                        else tt += A[0];
                        A[a[i]]++;
                        tt %= mo;
                }
                ans = ans + ((1ll << ti) % mo) * tt % mo;
                ans %= mo;
                A[0]=A[1]=0;
        }
        cout << ans << "\n";
}
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF  = 1e9;
constexpr llong  LINF = 1e18;
constexpr double EPS  = 1e-12;
constexpr int    MOD  = 1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a)cerr<<(cnt++?' ':'>')<<elem;cerr<<endl;}

int main(){//I refer to other commentaries.
	int n;
	string s,x;
	cin>>n>>s>>x;

	vector<set<int> > dp(n+1);
	dp[n].insert(0);
	for(int i=n-1;i>=0;--i){
		int num=s[i]-'0';
		if(x[i]=='A'){
			REP(res,7){
				bool jud=true;
				if(dp[i+1].find(res*10%7)==dp[i+1].end()) jud=false;
				if(dp[i+1].find((res*10+num)%7)==dp[i+1].end()) jud=false;
				if(jud) dp[i].insert(res);
			}
		}else{
			REP(res,7){
				bool jud=false;
				if(dp[i+1].find(res*10%7)!=dp[i+1].end()) jud=true;
				if(dp[i+1].find((res*10+num)%7)!=dp[i+1].end()) jud=true;
				if(jud) dp[i].insert(res);
			}
		}
	}

	bool ans=(dp[0].find(0)==dp[0].end());
	cout<<(ans?"Aoki":"Takahashi")<<endl;
}