
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ld> vld;
typedef pair<int,int> Pin;
typedef long long ll;

ll INF = 3e18;
int inf = 1e9;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

template <typename T>
void print(vector<T>& x) {
    int N = x.size();
    REP(i, N) {
        if (i > 0) cout << " ";
        cout << x[i];
    }
    cout << "\n";
}

/// unrolled extgcd.
/// Solve ax + by = gcd(a, b) and return gcd(a, b).
/// x and y are returned as given args.
/// Note that a^-1 mod n can be calculated by x of extgcd(a, n, x, y)
ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll u[] = {a, 1, 0}; ll v[] = {b, 0, 1};
    while(*v) {
        ll t = *u / *v;
        REP(i, 3) swap(u[i]-=t * v[i], v[i]);
    }
    x = u[1]; y = u[2];
    return u[0]; // return gcd of a and b
}

ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

/// solve x ≡ t_i mod m_i.
/// return {ans, lcm} if there is an answer.
/// Otherwise, return {0, -1}.
pair<ll, ll> crt(const vector<ll>& r, const vector<ll>& m) {
    assert(r.size() == m.size());
    ll r0 = 0, m0 = 1; // rem == ans, lcm
    REP(i, (int) r.size()) {
        assert(1 <= m[i]);
        ll r1 = mod(r[i], m[i]), m1 = m[i];

        if (m0 < m1) swap(m0, m1), swap(r0, r1);

        if (m0 % m1 == 0) {
            if (r0 % m1 != r1) return {0, -1};
            continue;
        }

        ll x, y;
        ll g = extgcd(m0, m1, x, y);
        if ((r1 - r0) % g) return {0, -1};

        ll u1 = m1 / g;
        ll tmp = (r1 - r0) / g % u1 * x % u1;
        r0 += m0 * tmp;
        m0 *= u1;
        if (r0 < 0) r0 += m0;
    }

    return {mod(r0, m0), m0}; // => {rem, lcm}
}

void solve() {
    ll x, y, p, q;
    cin >> x >> y >> p >> q;

    ll ans = -1;
    FOR(t1, p, p + q) {
        FOR(t2, x, x + y) {
            auto [t, lcm] = crt({t1, t2}, {p + q, 2 * (x + y)});
            if (lcm == -1) continue;
            if (ans == -1) ans = t;
            else ans = min(ans, t);
        }
    }

    if (ans == -1) print("infinity");
    else print(ans);

}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int t; cin >> t;

    while(t--) solve();
    
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define sz(x) ((ll)(x).size())
#define ceil(x, y) (((x)+(y)-1) / (y))
#define all(x) (x).begin(),(x).end()
#define outl(...) dump_func(__VA_ARGS__)
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<ll, ll> P;
bool exceed(ll x, ll y, ll m){return x >= m / y + 1;}

struct edge{
	ll to, cost;
	edge(){}
	edge(ll a, ll b){
		to = a, cost = b;
	}
};

template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for(int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
	for(typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end(); itr++) {
		os << "(" << itr->first << ", " << itr->second << ")";
		itr++;
		if(itr != map_var.end()) os << ",";
		itr--;
	}
	return os;
}
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
	for(typename set<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) {
		os << *itr;
		++itr;
		if(itr != set_var.end()) os << " ";
		itr--;
	}
	return os;
}
void dump_func() {cout << endl;}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    cout << head;
    if(sizeof...(Tail) > 0) cout << " ";
    dump_func(std::move(tail)...);
}

ll n;
string s, x;
ll dp[200005][7];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> s >> x;
	s = "#" + s, x = "#" + x;
	
	dp[n][0] = 1;
	rep(i, 1, 6) dp[n][i] = -1;
	
	for(int i = n-1; i >= 0; i--){
		rep(j, 0, 6){
			if(x[i+1] == 'T') dp[i][j] = max(dp[i+1][j*10%7], dp[i+1][(j*10+s[i+1]-'0')%7]);
			if(x[i+1] == 'A') dp[i][j] = min(dp[i+1][j*10%7], dp[i+1][(j*10+s[i+1]-'0')%7]);
		}
	}
	
	if(dp[0][0] > 0) outl("Takahashi");
	if(dp[0][0] < 0) outl("Aoki");
	
	return 0;
}