#include <bits/stdc++.h>
using namespace  std;
#define NMAX 200005
int n;
string s, x;
set <int> dp[NMAX];

int main() {
    cin>>n;
    cin>>s>>x;
    dp[n].insert(0);
    for(int i = n-1 ; i >= 0; i--){
        if(x[i]=='T'){
            for(int j=0;j<7;j++){
                int p = (10*j)%7;
                int q = ((10*j)+(s[i]-'0'))%7;
                if(dp[i+1].count(p)) {
                    dp[i].insert(j);
                    //cout<<i<<": insert "<<j<<'\n';
                }
                if(dp[i+1].count(q)) {
                    dp[i].insert(j);
                    //cout<<i<<": insert "<<j<<'\n';
                }
            }
        }
        else{
            for(int j=0;j<7;j++){
                int p = (10*j)%7;
                int q = ((10*j)+(s[i]-'0'))%7;
                if(dp[i+1].count(p) && dp[i+1].count(q)) {
                    dp[i].insert(j);
                    //cout<<i<<": insert "<<j<<'\n';
                }
            }
        }
    }
    if(dp[0].count(0)) cout<<"Takahashi";
    else cout<<"Aoki";
}

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

void solveCase() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  vector<bool> visit(26);
  for (auto& c : s1) visit[c - 'a'] = 1;
  for (auto& c : s2) visit[c - 'a'] = 1;
  for (auto& c : s3) visit[c - 'a'] = 1;
  vector<int> can;
  for (int k = 0; k < 26; ++k) {
    if (visit[k]) can.push_back(k);
  }
  int SZ = can.size();
  if (SZ > 10) {
    cout << "UNSOLVABLE" << '\n';
    return;
  }
 
  vector<int> p(10), v(26);
  int64_t x, y, z;
  for (int i = 0; i < 10; ++i) p[i] = i;
  bool found = false;
  do {
    for (int i = 0; i < SZ; ++i) v[can[i]] = p[i];
    x = 0, y = 0, z = 0;
    if (v[s1[0] - 'a'] == 0) continue;
    if (v[s2[0] - 'a'] == 0) continue;
    if (v[s3[0] - 'a'] == 0) continue;
    for (auto& c : s1) x = x * 10 + v[c - 'a'];
    for (auto& c : s2) y = y * 10 + v[c - 'a'];
    for (auto& c : s3) z = z * 10 + v[c - 'a'];
    if (x && y && z && x + y == z) {
      found = true;
      break;
    }
  } while (next_permutation(p.begin(), p.end()));
  if (!found) {
    cout << "UNSOLVABLE" << '\n';
  } else {
    cout << x << '\n';
    cout << y << '\n';
    cout << z << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int T = 1;
  // cin >> T;
  for (int ti = 1; ti <= T; ++ti) {
    // cout << "Case #" << ti << ": ";
    solveCase();
  }

  return 0;
}