#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n;
string s,t;
int main(){
        cin>>n>>s>>t;
        reverse(s.begin(),s.end());
        reverse(t.begin(),t.end());
        s=" "+s;t=" "+t;
        int base=1;
        bool con[10],tmp[10];
        for(int i=0;i<10;i++)con[i]=0,tmp[i]=0;
        con[0]=1;
        for(int i=1;i<=n;i++){
                if(t[i]=='T'){
                        for(int i=0;i<10;i++)tmp[i]=0;
                        int add=base*(s[i]-'0')%7;
                        for(int i=0;i<7;i++)if(con[i])tmp[(i+add)%7]=1;
                        for(int i=0;i<7;i++)if(tmp[i])con[i]=1,tmp[i]=0;
                }else{
                        bool tmp[2][10];
                        for(int i=0;i<7;i++)tmp[0][i]=tmp[1][i]=0;
                        int add=base*(s[i]-'0')%7;
                        for(int i=0;i<7;i++)if(con[i])tmp[0][i]=1,tmp[1][(i+add)%7]=1;
                        for(int i=0;i<7;i++)con[i]=(tmp[0][i]&&tmp[1][i]);
                }
                base=base*10%7;
        }
        if(con[0])cout<<"Takahashi\n";
        else cout<<"Aoki\n";
        return 0;
}
#include<bits/stdc++.h>
using namespace std;
void __print(int x){cout<<x;}void __print(long x){cout<<x;}
void __print(long long x){cout<<x;}void __print(unsigned x){cout<<x;}
void __print(unsigned long x){cout<<x;}void __print(unsigned long long x){cout<<x;}
void __print(float x){cout<<x;}void __print(double x){cout<<x;}
void __print(long double x){cout<<x;}void __print(char x){cout<<'\''<<x<<'\'';}
void __print(const char *x){cout<<'\"'<<x<<'\"';}void __print(const string &x){cout<<'\"'<<x<<'\"';}
void __print(bool x) {cout<<(x?"true":"false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
           
#define lp(i,a,b)       for (ll i=a;i<=b;i++)
#define rp(i,a,b)       for (ll i=a;i>=b;i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long 
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           ((a)*(a)*(a))
#define sz(a)           (int) a.size()
#define mod             1000000007
#define PI              (2*acos(0.0))
const ll N=2e5+5;
vector<array<ll,2>> g[N];
ll A[N];
void dfs(ll node,ll p,ll x)
{
  A[node]=x;
  for(auto [adj,cost]:g[node])
  {
    if(adj!=p) dfs(adj,node,x^cost);
  }
}
void solve() 
{
  ll n;
  cin>>n;
  lp(i,1,n-1)
  {
    ll a,b,c;
    cin>>a>>b>>c;
    g[a].pb({b,c});
    g[b].pb({a,c});
  }
  dfs(1,-1,0);
  ll res=0;
  lp(i,0,60)
  {
    ll one=0,zero=0;
    lp(j,1,n)
    {
          if(A[j] & 1ll<<i) one++;
          else zero++;
    }
    res=((res)+(1ll<<i)%mod*one%mod*zero%mod)%mod;
  }
  cout<<res;
}

int main()
{
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); cout.tie(NULL);
  int T=1;
  //cin>>T;
  while(T--) solve();
}
