A - Equal Hamming Distances

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

以下では、01 のみからなる文字列を 01 列と呼びます。

2 つの長さ N01S, T が与えられます。 下記の条件を満たす長さ N01U のうち辞書順最小のものを出力してください。

  • SU のハミング距離は、TU のハミング距離に等しい。

ただし、そのような長さ N01U が存在しない場合は、代わりに -1 を出力してください。

ハミング距離とは?

01X = X_1X_2\ldots X_N01Y = Y_1Y_2\ldots Y_Nハミング距離は、X_i \neq Y_i を満たす整数 1 \leq i \leq N の個数です。

辞書順とは?

01X = X_1X_2\ldots X_N01Y = Y_1Y_2\ldots Y_N より辞書順で小さいとは、下記の 2 つの条件をともに満たす整数 1 \leq i \leq N が存在することを言います。

  • X_1X_2\ldots X_{i-1} = Y_1Y_2\ldots Y_{i-1}
  • X_i = 0 かつ Y_i = 1

制約

  • 1 \leq N \leq 2 \times 10^5
  • N は整数
  • S, T は長さ N01

入力

入力は以下の形式で標準入力から与えられる。

N
S
T

出力

問題文中の条件を満たす長さ N01U のうち辞書順最小のものを出力せよ。 ただし、そのような 01U が存在しない場合は、代わりに -1 を出力せよ。


入力例 1

5
00100
10011

出力例 1

00001

U = 00001とおくと、SU のハミング距離と、TU のハミング距離はどちらも 2 です。 また、これが問題文中の条件を満たす長さ N01U のうち辞書順最小です。


入力例 2

1
0
1

出力例 2

-1

問題文中の条件を満たす長さ N01U が存在しないため、-1 を出力します。

Score : 300 points

Problem Statement

Below, a 01-sequence is a string consisting of 0 and 1.

You are given two 01-sequences S and T of length N each. Print the lexicographically smallest 01-sequence U of length N that satisfies the condition below.

  • The Hamming distance between S and U equals the Hamming distance between T and U.

If there is no such 01-sequence U of length N, print -1 instead.

What is Hamming distance?

The Hamming distance between 01-sequences X = X_1X_2\ldots X_N and Y = Y_1Y_2\ldots Y_N is the number of integers 1 \leq i \leq N such that X_i \neq Y_i.

What is lexicographical order?

A 01-sequence X = X_1X_2\ldots X_N is lexicographically smaller than a 01-sequence Y = Y_1Y_2\ldots Y_N when there is an integer 1 \leq i \leq N that satisfies both of the conditions below.

  • X_1X_2\ldots X_{i-1} = Y_1Y_2\ldots Y_{i-1}.
  • X_i = 0 and Y_i = 1.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • N is an integer.
  • S and T are 01-sequences of length N each.

Input

The input is given from Standard Input in the following format:

N
S
T

Output

Print the lexicographically smallest 01-sequence U of length N that satisfies the condition in the Problem Statement, or -1 if there is no such 01-sequence U.


Sample Input 1

5
00100
10011

Sample Output 1

00001

For U = 00001, the Hamming distance between S and U and the Hamming distance between T and U are both 2. Additionally, this is the lexicographically smallest 01-sequence U of length N that satisfies the condition.


Sample Input 2

1
0
1

Sample Output 2

-1

No 01-sequence U of length N satisfies the condition, so -1 should be printed.

B - A < AP

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

(1, 2, \ldots, N) の順列 P = (P_1, P_2, \ldots, P_N) が与えられます。

下記の 2 つの条件をともに満たす長さ N の整数列 A = (A_1, A_2, \ldots, A_N) の個数を 998244353 で割ったあまりを出力してください。

  • すべての i = 1, 2, \ldots, N について、1 \leq A_i \leq M
  • 整数列 A は整数列 (A_{P_1}, A_{P_2}, \ldots, A_{P_N}) より辞書順で小さい。
辞書順で小さいとは?

整数列 X = (X_1, X_2, \ldots, X_N) が 整数列 Y = (Y_1, Y_2, \ldots, Y_N) より辞書順で小さいとは、下記の 2 つの条件をともに満たす整数 1 \leq i \leq N が存在することを言います。

  • 1 \leq j \leq i-1 を満たすすべての整数 j について、X_j = Y_j
  • X_i \lt Y_i

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 10^9
  • 1 \leq P_i \leq N
  • i \neq j \implies P_i \neq P_j
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N M
P_1 P_2 \ldots P_N

出力

問題文中の 2 つの条件をともに満たす整数列 A の個数を 998244353 で割ったあまりを出力せよ。


入力例 1

4 2
4 1 3 2

出力例 1

6

問題文中の 2 つの条件をともに満たす整数列 A は、 (1, 1, 1, 2), (1, 1, 2, 2), (1, 2, 1, 2), (1, 2, 2, 2), (2, 1, 1, 2), (2, 1, 2, 2)6 個です。
例えば、A = (1, 1, 1, 2) のとき、(A_{P_1}, A_{P_2}, A_{P_3}, A_{P_4}) = (2, 1, 1, 1) であり、これは A より辞書順で大きいです。


入力例 2

1 1
1

出力例 2

0

入力例 3

20 100000
11 15 3 20 17 6 1 9 5 19 10 16 7 8 12 2 18 14 4 13

出力例 3

55365742

Score : 500 points

Problem Statement

You are given a permutation P = (P_1, P_2, \ldots, P_N) of (1, 2, \ldots, N).

Print the number of integer sequences A = (A_1, A_2, \ldots, A_N) of length N that satisfy both of the conditions below, modulo 998244353.

  • 1 \leq A_i \leq M for every i = 1, 2, \ldots, N.
  • The integer sequence A is lexicographically smaller than the integer sequence (A_{P_1}, A_{P_2}, \ldots, A_{P_N}).
What is lexicographical order?

An integer sequence X = (X_1,X_2,\ldots,X_N) is lexicographically smaller than an integer sequence Y = (Y_1,Y_2,\ldots,Y_N) when there is an integer 1 \leq i \leq N that satisfies both of the conditions below.

  • For all integers j (1 \leq j \leq i-1), X_j=Y_j.
  • X_i < Y_i

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 10^9
  • 1 \leq P_i \leq N
  • i \neq j \implies P_i \neq P_j
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

N M
P_1 P_2 \ldots P_N

Output

Print the number of integer sequences A of length N that satisfy both of the conditions in the Problem Statement, modulo 998244353.


Sample Input 1

4 2
4 1 3 2

Sample Output 1

6

Six integer sequences A satisfy both of the conditions: (1, 1, 1, 2), (1, 1, 2, 2), (1, 2, 1, 2), (1, 2, 2, 2), (2, 1, 1, 2), and (2, 1, 2, 2).
For instance, when A = (1, 1, 1, 2), we have (A_{P_1}, A_{P_2}, A_{P_3}, A_{P_4}) = (2, 1, 1, 1), which is lexicographically larger than A.


Sample Input 2

1 1
1

Sample Output 2

0

Sample Input 3

20 100000
11 15 3 20 17 6 1 9 5 19 10 16 7 8 12 2 18 14 4 13

Sample Output 3

55365742
C - 01 Game

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

マス 1 、マス 2\ldots 、マス NN 個のマスがあり、 i = 1, 2, \ldots, N-1 についてマス i とマス i+1 は隣り合っています。

はじめ、M 個のマスには 0 または 1 が書かれています。 具体的には、i = 1, 2, \ldots, M について、マス X_iY_i が書かれています。 また、その他の N-M 個のマスには何も書かれていません。

高橋君と青木君が 2 人で対戦ゲームをします。 高橋君の先手で、2 人は交互に下記の行動を行います。

  • まだ何も書かれていないマスを 1 つ選び、そのマスに 0 または 1 を書きこむ。 ただしその結果、ある 2 つの隣り合うマスに同じ数字が書かれた状態になってはならない。

先に行動することができなくなったプレイヤーの負けとなり、負けなかったプレイヤーの勝ちとなります。

両者がそれぞれ自身が勝つために最適な戦略をとる場合に、どちらが勝つかを判定してください。

制約

  • 1 \leq N \leq 10^{18}
  • 0 \leq M \leq \min\lbrace N, 2 \times 10^5 \rbrace
  • 1 \leq X_1 \lt X_2 \lt \cdots \lt X_M \leq N
  • Y_i \in \lbrace 0, 1\rbrace
  • X_i + 1 = X_{i+1} \implies Y_i \neq Y_{i+1}
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N M
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M

出力

高橋君が勝つ場合は Takahashi を、青木君が勝つ場合は Aoki を出力せよ。


入力例 1

7 2
2 0
4 1

出力例 1

Takahashi

ゲームの進行の一例を示します。

  1. 高橋君がマス 60 を書きこむ。
  2. 青木君がマス 11 を書きこむ。
  3. 高橋君がマス 71 を書きこむ。

その後、青木君はどのマスにも 0 または 1 を書きこむことが出来ないため、高橋君の勝ちとなります。


入力例 2

3 3
1 1
2 0
3 1

出力例 2

Aoki

ゲーム開始時点ですでにすべてのマスに 0 または 1 が書きこまれているため、先手の高橋君は行動できず青木君の勝ちとなります。


入力例 3

1000000000000000000 0

出力例 3

Aoki

Score : 600 points

Problem Statement

There are N squares called square 1, square 2, \ldots, square N, where square i and square i+1 are adjacent for each i = 1, 2, \ldots, N-1.

Initially, M of the squares have 0 or 1 written on them. Specifically, for each i = 1, 2, \ldots, M, Y_i is written on square X_i. The other N-M squares have nothing written on them.

Takahashi and Aoki will play a game against each other. The two will alternately act as follows, with Takahashi going first.

  • Choose a square with nothing written yet, and write 0 or 1 on that square. Here, it is forbidden to make two adjacent squares have the same digit written on them.

The first player to be unable to act loses; the other player wins.

Determine the winner when both players adopt the optimal strategy for their own victory.

Constraints

  • 1 \leq N \leq 10^{18}
  • 0 \leq M \leq \min\lbrace N, 2 \times 10^5 \rbrace
  • 1 \leq X_1 \lt X_2 \lt \cdots \lt X_M \leq N
  • Y_i \in \lbrace 0, 1\rbrace
  • X_i + 1 = X_{i+1} \implies Y_i \neq Y_{i+1}
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

N M
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M

Output

If Takahashi wins, print Takahashi; if Aoki wins, print Aoki.


Sample Input 1

7 2
2 0
4 1

Sample Output 1

Takahashi

Here is one possible progression of the game.

  1. Takahashi writes 0 on square 6.
  2. Aoki writes 1 on square 1.
  3. Takahashi writes 1 on square 7.

Then, Aoki cannot write 0 or 1 on any square, so Takahashi wins.


Sample Input 2

3 3
1 1
2 0
3 1

Sample Output 2

Aoki

Since every square already has 0 or 1 written at the beginning, Takahashi, who goes first, cannot act, so Aoki wins.


Sample Input 3

1000000000000000000 0

Sample Output 3

Aoki
D - Binary Representations and Queries

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 700

問題文

長さ 2^N の整数列 A = (A_0, A_1, \ldots, A_{2^N-1}) が与えられます。

また、Q 個のクエリが与えられます。 i = 1, 2, \ldots, Q について、i 番目のクエリでは 2 つの整数 X_i, Y_i が与えられ、下記の操作を行います。

j = 0, 1, 2, \ldots, 2^N-1 の順に下記の手順を行う。

  1. まず、jN 桁の 2 進数表現を b_{N-1}b_{N-2}\ldots b_0 とおく。また、b_{N-1}b_{N-2}\ldots b_0 から b_{X_i} を反転( 0 ならば 1 に、1 ならば 0 に変更)させて得られる 2 進数表現によって表される整数を j' とおく。

  2. そして、b_{X_i} = Y_i ならば、A_{j'}A_j の値を加算する。

すべてのクエリを入力で与えられる順番に実行した後の A の各要素を 998244353 で割ったあまりを出力してください。

N 桁の 2 進数表現とは?

非負整数 X (0 \leq X < 2^N) の N 桁の 2 進数表現とは、01 のみからなり下記の条件を満たす唯一の、長さ N の列 b_{N-1}b_{N-2}\ldots b_0です。

  • \sum_{i = 0}^{N-1} b_i \cdot 2^i = X

制約

  • 1 \leq N \leq 18
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq A_i \lt 998244353
  • 0 \leq X_i \leq N-1
  • Y_i \in \lbrace 0, 1\rbrace
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N Q
A_0 A_1 \ldots A_{2^N-1}
X_1 Y_1
X_2 Y_2
\vdots
X_Q Y_Q

出力

i = 0, 1, \ldots, 2^N-1 について、すべてのクエリを実行した後の A_i998244353 で割ったあまり A'_i を、下記の形式にしたがって空白区切りで出力せよ。

A'_0 A'_1 \ldots A'_{2^N-1}

入力例 1

2 2
0 1 2 3
1 1
0 0

出力例 1

2 6 2 5

1 番目のクエリに対する操作は次の通りです。

  • j = 0 のとき、b_1b_0 = 00, j' = 2 です。b_1 \neq 1 であるので、加算の手順は行いません。
  • j = 1 のとき、b_1b_0 = 01, j' = 3 です。b_1 \neq 1 であるので、加算の手順は行いません。
  • j = 2 のとき、b_1b_0 = 10, j' = 0 です。b_1 = 1 であるので、A_0A_2 の値を加算します。その結果、A = (2, 1, 2, 3) となります。
  • j = 3 のとき、b_1b_0 = 11, j' = 1 です。b_1 = 1 であるので、A_1A_3 の値を加算します。その結果、A = (2, 4, 2, 3) となります。

2 番目のクエリに対する操作は次の通りです。

  • j = 0 のとき、b_1b_0 = 00, j' = 1 です。b_0 = 0 であるので、A_1A_0 の値を加算します。その結果、A = (2, 6, 2, 3) となります。
  • j = 1 のとき、b_1b_0 = 01, j' = 0 です。b_0 \neq 0 であるので、加算の手順は行いません。
  • j = 2 のとき、b_1b_0 = 10, j' = 3 です。b_0 = 0 であるので、A_3A_2 の値を加算します。その結果、A = (2, 6, 2, 5) となります。
  • j = 3 のとき、b_1b_0 = 11, j' = 2 です。b_0 \neq 0 であるので、加算の手順は行いません。

以上より、すべてのクエリを実行した後の A(2, 6, 2, 5) です。


入力例 2

3 10
606248357 338306877 919152167 981537317 808873985 845549408 680941783 921035119
1 1
0 0
0 0
0 0
0 1
0 1
0 1
2 0
2 0
2 0

出力例 2

246895115 904824001 157201385 744260759 973709546 964549010 61683812 205420980

Score : 700 points

Problem Statement

You are given an integer sequence A = (A_0, A_1, \ldots, A_{2^N-1}) of length 2^N.

Additionally, Q queries are given. For each i = 1, 2, \ldots, Q, the i-th query is represented by two integers X_i and Y_i and asks you to perform the operation below.

For each j = 0, 1, 2, \ldots, 2^N-1 in this order, do the following.

  1. First, let b_{N-1}b_{N-2}\ldots b_0 be the binary representation of j with N digits. Additionally, let j' be the integer represented by the binary representation b_{N-1}b_{N-2}\ldots b_0 after flipping the bit b_{X_i} (changing 0 to 1 and 1 to 0).
  2. Then, if b_{X_i} = Y_i, add the value of A_j to A_{j'}.

Print each element of A, modulo 998244353, after processing all the queries in the order they are given in the input.

What is binary representation with N digits?

The binary representation of an non-negative integer X (0 \leq X < 2^N) with N digits is the unique sequence b_{N-1}b_{N-2}\ldots b_0 of length N consisting of 0 and 1 that satisfies:

  • \sum_{i = 0}^{N-1} b_i \cdot 2^i = X.

Constraints

  • 1 \leq N \leq 18
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq A_i \lt 998244353
  • 0 \leq X_i \leq N-1
  • Y_i \in \lbrace 0, 1\rbrace
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

N Q
A_0 A_1 \ldots A_{2^N-1}
X_1 Y_1
X_2 Y_2
\vdots
X_Q Y_Q

Output

For each i = 0, 1, \ldots, 2^N-1, print the remainder A'_i when dividing A_i after processing all the queries by 998244353, separated by spaces, in the following format:

A'_0 A'_1 \ldots A'_{2^N-1}

Sample Input 1

2 2
0 1 2 3
1 1
0 0

Sample Output 1

2 6 2 5

The first query asks you to do the following.

  • For j = 0, we have b_1b_0 = 00 and j' = 2. Since b_1 \neq 1, skip the addition.
  • For j = 1, we have b_1b_0 = 01 and j' = 3. Since b_1 \neq 1, skip the addition.
  • For j = 2, we have b_1b_0 = 10 and j' = 0. Since b_1 = 1, add the value of A_2 to A_0. Now we have A = (2, 1, 2, 3).
  • For j = 3, we have b_1b_0 = 11 and j' = 1. Since b_1 = 1, add the value of A_3 to A_1. Now we have A = (2, 4, 2, 3).

The second query asks you to do the following.

  • For j = 0, we have b_1b_0 = 00 and j' = 1. Since b_0 = 0, add the value of A_0 to A_1. Now we have A = (2, 6, 2, 3).
  • For j = 1, we have b_1b_0 = 01 and j' = 0. Since b_0 \neq 0, skip the addition.
  • For j = 2, we have b_1b_0 = 10 and j' = 3. Since b_0 = 0, add the value of A_2 to A_3. Now we have A = (2, 6, 2, 5).
  • For j = 3, we have b_1b_0 = 11 and j' = 2. Since b_0 \neq 0, skip the addition.

Thus, A will be (2, 6, 2, 5) after processing all the queries.


Sample Input 2

3 10
606248357 338306877 919152167 981537317 808873985 845549408 680941783 921035119
1 1
0 0
0 0
0 0
0 1
0 1
0 1
2 0
2 0
2 0

Sample Output 2

246895115 904824001 157201385 744260759 973709546 964549010 61683812 205420980
E - Keep Being Substring

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 700

問題文

長さ N の整数列 A = (A_1, A_2, \ldots, A_N) が与えられます。 また、A の長さ P の連続な部分列 X = (X_1, X_2, \ldots, X_P) と、A の長さ Q の連続な部分列 Y = (Y_1, Y_2, \ldots, Y_Q) が与えられます。

X に対して、下記の 4 つのいずれかを行うという操作を、好きな回数( 0 回でも良い)だけ行うことができます。

  • X の先頭に任意の整数を 1 つ追加する。
  • X の先頭の要素を削除する。
  • X の末尾に任意の整数を 1 つ追加する。
  • X の末尾の要素を削除する。

ただし、各操作の前後において、XA空でない連続な部分列でなければなりません。 XY と一致させるために行う操作回数の最小値を求めてください。 なお、本問題の制約下において、操作の繰り返しによって XY を必ず一致させられることが証明できます。

連続な部分列とは?

数列 X = (X_1, X_2, \ldots, X_P) が数列 A = (A_1, A_2, \ldots, A_N)連続な部分列であるとは、1 \leq l \leq N-P+1 を満たす整数 l が存在して、 すべての i = 1, 2, \ldots, P について、X_i = A_{l+i-1} が成り立つことです。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq N
  • 1 \leq P, Q \leq N
  • (X_1, X_2, \ldots, X_P)(Y_1, Y_2, \ldots, Y_Q) は、(A_1, A_2, \ldots, A_N) の連続な部分列
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 \ldots A_N
P
X_1 X_2 \ldots X_P
Q
Y_1 Y_2 \ldots Y_Q

出力

答えを出力せよ。


入力例 1

7
3 1 4 1 5 7 2
2
3 1
3
1 5 7

出力例 1

3

下記の手順で操作すると、XA の空でない連続な部分列であるという条件を満たしたまま、XY に一致させることが出来ます。

  1. まず、X の先頭の要素を削除する。その結果、X = (1) となる。
  2. 次に、X の末尾に 5 を追加する。その結果、X = (1, 5) となる。
  3. さらに、X の 末尾に 7 を追加する。その結果、X = (1, 5, 7) となり、XY と一致する。

上記の手順の操作回数は 3 回であり、これが考えられる最小の操作回数です。


入力例 2

20
2 5 1 2 7 7 4 5 3 7 7 4 5 5 5 4 6 5 6 1
6
1 2 7 7 4 5
7
7 4 5 5 5 4 6

出力例 2

7

Score : 700 points

Problem Statement

You are given an integer sequence A = (A_1, A_2, \ldots, A_N) of length N. Additionally, its contiguous subsequences of lengths P and Q are given: X = (X_1, X_2, \ldots, X_P) and Y = (Y_1, Y_2, \ldots, Y_Q).

You can perform the four operations on X below any number of times (possibly zero) in any order.

  • Add an arbitrary integer at the beginning of X.
  • Delete the element at the beginning of X.
  • Add an arbitrary integer at the end of X.
  • Delete the element at the end of X.

Here, X must be a non-empty contiguous subsequence of A before and after each operation. Find the minimum total number of operations needed to make X equal Y. Under the Constraints of this problem, it is guaranteed that one can always make X equal Y by repeating operations.

What is a contiguous subsequence?

A sequence X = (X_1, X_2, \ldots, X_P) is a contiguous subsequence of A = (A_1, A_2, \ldots, A_N) when there is an integer l satisfying 1 \leq l \leq N-P+1 such that X_i = A_{l+i-1} for every i = 1, 2, \ldots, P.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq N
  • 1 \leq P, Q \leq N
  • (X_1, X_2, \ldots, X_P) and (Y_1, Y_2, \ldots, Y_Q) are contiguous subsequences of (A_1, A_2, \ldots, A_N).
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N
P
X_1 X_2 \ldots X_P
Q
Y_1 Y_2 \ldots Y_Q

Output

Print the answer.


Sample Input 1

7
3 1 4 1 5 7 2
2
3 1
3
1 5 7

Sample Output 1

3

You can make X equal Y while keeping X a non-empty contiguous subsequence of A, as follows.

  1. First, delete the element at the beginning of X. Now, you have X = (1).
  2. Next, add 5 at the end of X. Now, you have X = (1, 5).
  3. Furthermore, add 7 at the end of X. Now, you have X = (1, 5, 7), which equal Y.

Here, you perform three operations, which is the fewest possible.


Sample Input 2

20
2 5 1 2 7 7 4 5 3 7 7 4 5 5 5 4 6 5 6 1
6
1 2 7 7 4 5
7
7 4 5 5 5 4 6

Sample Output 2

7
F - RGB Card Game

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 1000

問題文

赤、緑、青の 3 色のカードを使って、高橋君と青木君が 2 人で対戦ゲームをします。

はじめ、赤、緑、青のカードを、高橋君はそれぞれ R_1, G_1, B_1 枚ずつ、青木君はそれぞれ R_2, G_2, B_2 枚ずつ手札に持っています。 なお、2 人は互いの手札の内容を把握しています。 ゲームでは、高橋君が「攻め」、青木君が「守り」を担当する状態から開始し、下記の手順を繰り返します。

  1. まず、攻めを担当するプレイヤーが好きなカード 1 枚を手札から場に出す。
  2. その後、守りを担当するプレイヤーは、そのカードと同じ色のカード 1 枚を手札から場に出すか、何もしないかを選択する。もしカードを出した場合は、2 人は攻めと守りの担当を交代する。

ある時点で先に手札が 0 枚になったプレイヤーの勝ちです。両者がそれぞれ自身が勝つために最適な戦略をとる場合にどちらが勝つかを求めてください。

一つの入力ファイルにつき、T 個の独立なテストケースに答えてください。

制約

  • 1 \leq T \leq 10^5
  • 0 \leq R_1, G_1, B_1, R_2, G_2, B_2 \leq 10^{18}
  • R_1 + G_1 + B_1 \geq 1
  • R_2 + G_2 + B_2 \geq 1
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

各テストケースは以下の形式で与えられる。

R_1 G_1 B_1 R_2 G_2 B_2

出力

各テストケースについて、高橋君が勝つ場合は Takahashi を、青木君が勝つ場合は Aoki を出力せよ。


入力例 1

10
1 1 1 0 1 2
1 2 3 4 5 6
1 2 3 3 2 1
1 0 1 0 1 0
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
711741968710511023 863182190136397525 935042422763027373 565732706644706921 453428280447672223 188382995979861200
166020598057882490 762504522442931582 957390622951053643 932567512152300679 473764934043971365 82803157126515469
895348321962139989 376963632541282296 624486091834022571 175064808312523035 217537722506696493 203742827664922704
802346905414720749 973713209304621356 275109783325269828 588060532191410837 516874290286751783 747001196732741840
539971830806602684 270896673960719346 124580938028911221 18175990488280605 360214649380675201 155957964634289774

出力例 1

Takahashi
Takahashi
Aoki
Takahashi
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi

1 つ目のテストケースについて、ゲームの進行の一例を示します。

  1. 攻めを担当する高橋君が赤のカードを場に出す。
  2. それに対して、守りを担当する青木君は、何もしないことを選択する。(青木君は赤のカードを持っていないため、何もしないことを選択することしかできません。)
  3. 攻めを担当する高橋君が緑のカードを場に出す。
  4. それに対して、守りを担当する青木君は、緑のカードを場に出す。2 人は攻めと守りの担当を交代する。
  5. 攻めを担当する青木君が青のカードを場に出す。
  6. それに対して、守りを担当する高橋君は、青のカードを場に出す。
  7. 高橋君の手札が先に 0 枚になったため、高橋君の勝ちとなる。

Score : 1000 points

Problem Statement

Takahashi and Aoki will play a game against each other using cards in three colors: red, green, and blue.

Initially, Takahashi has R_1 red, G_1 green, and B_1 blue cards, and Aoki has R_2 red, G_2 green, and B_2 blue cards in their hands. Each player knows the hands of both players. The game starts with Takahashi on offense and Aoki on defense, and repeats the process below.

  1. First, the player on offense plays an arbitrary card from his hand.
  2. Then, the player on defense either plays a card with the same color from his hand, or does nothing. If a card is played, the players switch between offense and defense.

The first player to have zero cards in his hand wins the game. Determine the winner when both players adopt the optimal strategy for their own victory.

For each input file, solve T independent test cases.

Constraints

  • 1 \leq T \leq 10^5
  • 0 \leq R_1, G_1, B_1, R_2, G_2, B_2 \leq 10^{18}
  • R_1 + G_1 + B_1 \geq 1
  • R_2 + G_2 + B_2 \geq 1
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

Each test case is in the following format:

R_1 G_1 B_1 R_2 G_2 B_2

Output

For each test case, print Takahashi if Takahashi wins, and Aoki if Aoki wins.


Sample Input 1

10
1 1 1 0 1 2
1 2 3 4 5 6
1 2 3 3 2 1
1 0 1 0 1 0
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
711741968710511023 863182190136397525 935042422763027373 565732706644706921 453428280447672223 188382995979861200
166020598057882490 762504522442931582 957390622951053643 932567512152300679 473764934043971365 82803157126515469
895348321962139989 376963632541282296 624486091834022571 175064808312523035 217537722506696493 203742827664922704
802346905414720749 973713209304621356 275109783325269828 588060532191410837 516874290286751783 747001196732741840
539971830806602684 270896673960719346 124580938028911221 18175990488280605 360214649380675201 155957964634289774

Sample Output 1

Takahashi
Takahashi
Aoki
Takahashi
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi

For the first test case, here is one possible progression of the game.

  1. Takahashi, who is on offense, plays a red card.
  2. Aoki, who is on defense, responds by doing nothing. (Since he has no red cards, this is the only choice.)
  3. Takahashi, who is on offense, plays a green card.
  4. Aoki, who is on defense, responds by playing a green card. The players switch between offense and defense.
  5. Aoki, who is on offense, plays a blue card.
  6. Takahashi, who is on defense, responds by playing a blue card.
  7. Takahashi is the first player to have zero cards in his hand, so he wins.