#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
 
int n;
string s,t;
 
bool dp[200007][3][10];
bool vis[200007][3][10];
 
bool rec( int i, bool aoki, int mod )
{
    if(i>=n)
    {
        if(mod)
            return 0;
        return 1;
    }
 
    if(vis[i][aoki][mod])
        return dp[i][aoki][mod];
 
    bool turn= aoki;
 
    if(t[i+1]=='T' and aoki)
        turn^= 1;
    else if(t[i+1]=='A' and !aoki)
        turn^= 1;
 
    bool ret1= rec( i+1, turn, (mod*10+s[i]-'0')%7 );
    bool ret2= rec( i+1, turn, (mod*10)%7 );
    
    // cout<<i<<" "<<aoki<<" "<<mod<<" "<<ret1<<" "<<ret2<<endl;
 
    vis[i][aoki][mod]= 1;
    bool ans;
 
    if( aoki )
    {
        if( ret1 and ret2 )
            ans= 1;
        else
            ans= 0;
    }
    else
    {
        if( ret1 or ret2 )
            ans= 1;
        else
            ans= 0;
    }
 
    return dp[i][aoki][mod]= ans;
}
 
int main()
{
    cin>>n;
    cin>>s>>t;
 
    t[n]= 'C';
 
    if(rec(0, t[0]=='A', 0))
        cout<<"Takahashi";
    else
        cout<<"Aoki";
}
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

class UnionFind {
  public:
    vi Parent;
    UnionFind(int N) {
      Parent = vi(N,-1);
    }
  
    int root(int A) {
      if(Parent[A] < 0) return A;
      return Parent[A] = root(Parent[A]);
    }
  
    int size(int A) {
      return -Parent[root(A)];
    }
  
    bool connect(int A,int B) {
      A = root(A);
      B = root(B);
      if(A == B) return false;
      if(size(A) < size(B)) swap(A,B);
      Parent[A] += Parent[B];
      Parent[B] = A;
      return true;
    }
};
  
int main() {
  int N,M;
  cin >> N >> M;
  vi A(N),B(N);
  rep(i,N) {
    cin >> A[i];
  }
  rep(i,N) {
    cin >> B[i];
  }
  vi c(M),d(M);
  rep(i,M) {
    cin >> c[i] >> d[i];
    c[i]--;
    d[i]--;
  }
  UnionFind uf(N);
  rep(i,M) {
    uf.connect(c[i],d[i]);
  }
  vl now(N,0),ans(N,0);
  rep(i,N) {
    now[uf.root(i)] += A[i];
    ans[uf.root(i)] += B[i];
  }
  rep(i,N) {
    if(now[i]!=ans[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}