Latakia and Tartus Collegiate Programming Contest 2025
A. Olives and Water
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Baran has a strip of land in the beautiful city of Afrin, a city renowned for its delicious olive oil, lush green nature, and generous people. Visitors to Afrin are always captivated by its stunning scenery.

Baran's land is represented as a single line of $$$n$$$ cells. Each cell can be in one of four states:

  • Empty ('.')
  • A fruitful olive tree ready for harvest ('O')
  • A tree that needs water ('T')
  • A bag of water ('W')

Baran plans to walk along this line of cells exactly once, from the first cell to the last. He has a vehicle that can carry a total of $$$M$$$ kilograms of items. For simplicity, we assume one bag of water weighs 1 kg and one unit of harvested olives also weighs 1 kg.

During his single pass, Baran has two objectives:

  1. He must water every single tree that needs it. To water a tree at cell $$$i$$$, he must have a bag of water in his vehicle. He must have picked up this bag from a cell $$$j \lt i$$$. Upon use, the bag of water is consumed and removed from the vehicle.
  2. He wants to collect the maximum possible amount of olives. He can choose to harvest any fruitful olive tree he encounters, which adds one unit of olives to his vehicle.

The total weight of water bags and olive units in his vehicle cannot exceed $$$M$$$ at any point in time.

Can you help Baran determine the maximum number of olive units he can collect while ensuring all needy trees are watered?

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 10^5$$$). The description of the $$$T$$$ test cases follows.

The first line of each test case contains two integers $$$N$$$ and $$$M$$$ ($$$1 \le N \le 10^5$$$, $$$1 \le M \le 10^5$$$), representing the number of cells in the land and the vehicle's capacity, respectively.

The second line of each test case contains a string of length $$$N$$$, describing the land. Each character is one of ., O, T, or W.

It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each test case, print a single integer on a new line. This integer should be the maximum number of olive units Baran can collect. If it is impossible to water all the trees that need it, print -1.

Example
Input
4
8 2
.OOWTWTO
7 2
TOOWTWT
5 3
.OOOO
12 3
OWWTWTTOOOOO
Output
2
-1
3
3
Note

First Test Case:

  • At index 2, he takes the first 'O'. Vehicle weight becomes 1.
  • At index 4, he takes 'W'. Vehicle weight becomes 2.
  • At index 5, he uses 'W' to water the tree at index 5. Vehicle weight becomes 1.
  • At index 6, he takes 'W'. Vehicle weight becomes 2.
  • At index 7, he uses 'W' to water the tree at index 7. Vehicle weight becomes 1.
  • At index 8, he takes 'O'. Vehicle weight becomes 2.

The number of 'O's inside the vehicle is 2, so the answer is: $$$2$$$

Second Test Case:

  • At index 1, there is a 'T', but he doesn't have any 'W'.
  • Therefore, he cannot water the tree at index 1.

The answer is: $$$-1$$$

Third Test Case:

  • He takes the 'O's from indices 2, 3, and 4. Vehicle weight becomes 3.
  • At index 5, he cannot take the 'O' because the vehicle weight is equal to $$$m$$$.

The answer is: $$$3$$$

Fourth Test Case:

  • At index 1 he takes the first 'O'. vehicle weight becomes 1.
  • At index 2,3 he takes the 'W'. vehicle weight become 3 , the vehicle has 1 'O' and 2 'W'.
  • at index 4 he use one from 'W' vehicle weight become 2 , the vehicle has 1 'O' and 1 'W'.
  • at index 5 he he takes the 'W' vehicle weight become 3 , the vehicle has 1 'O' and 2 'W'
  • at index's 6,7 he use 2 from 'W' vehicle weight become 1 , the vehicle has 1 'O' only.
  • at index's 8,9 he takes 2 'O' vehicle weight become 3 ,the vehicle has 3 'O' only.
  • at index's 10,11,12 he can't take any 'O' because the vehicle weight is equal to $$$m$$$. the answer is: $$$3$$$

B. Let's Go Swimming!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The judges have just landed in Latakia, and they don't want to waste any time, but they are really eager to go swimming in the sea!

So judge Apra proposed going swimming at time $$$a$$$, and judge Mouf proposed going swimming at time $$$b$$$, so they started fighting and couldn't decide on a suitable time.

After much fighting, they decided to go swimming at the minimum time so they get to make it to the contest, but they are currently busy preparing the problems, so can you help them choose the minimum time?

Input

The first and only line of input contains two integers $$$a$$$ and $$$b$$$ $$$(1 \le a, b \le 1000)$$$.

Output

Output a single number, the answer to the problem.

Example
Input
4 2
Output
2

C. Shortest Cycle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two integers, $$$n$$$ and $$$m$$$. Using these, we define two infinite, 1-indexed sequences, $$$A$$$ and $$$B$$$:

  • Sequence $$$A$$$ is the repeating sequence $$$[1, 2, \dots, n, 1, 2, \dots, n, \dots]$$$.
  • Sequence $$$B$$$ is the repeating sequence $$$[n + 1, n + 2, \dots, n + m, n + 1, n + 2, \dots, n + m, \dots]$$$.
This means for any index $$$i \ge 1$$$, $$$A_i = ((i-1) \pmod n) + 1$$$ and $$$B_i = ((i-1) \pmod m) + n + 1$$$.

Now, construct a graph with $$$n + m$$$ nodes. In this graph, there exists an undirected edge connecting node $$$u$$$ and node $$$v$$$ if and only if there exists some index $$$i \ge 1$$$ such that $$$A_i = u$$$ and $$$B_i = v$$$.

Note: a cycle is a path in a graph that starts and ends at the same vertex, with no repeated edges and at least one edge.

Your task is to find the smallest cycle in the resulting graph. If there are multiple cycles of the same smallest size, you may print any one of them. If the graph is acyclic, print -1.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 10^4$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ $$$(2 \le n, m \le 10^5)$$$.

It is guaranteed that the sum of $$$n$$$ and $$$m$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each test case, if the graph is acyclic print -1. Otherwise, in the first line print a single integer k $$$(3 \le k \le n + m)$$$ — the size of the smallest cycle in the graph. In the next line print k distinct integers $$$(c_1, c_2, ..., c_k)$$$, describing the cycle. for $$$1 \lt i \le k$$$ the node $$$c_i$$$ should be connected to the node $$$c_{i - 1}$$$. and node $$$c_k$$$ should be connected to node $$$c_1$$$.

It is guaranteed that the sum of $$$k$$$ over all test cases does not exceed $$$10^6$$$.

Example
Input
3
2 3
2 4
4 6
Output
4
1 5 2 3
-1
4
5 3 7 1
Note

Explanation of the example:

The first test case:

A = $$$[1, 2, 1, 2, 1, 2, ...]$$$

B = $$$[3, 4, 5, 3, 4, 5, ...]$$$

The second test case:

A = $$$[1, 2, 1, 2, 1, 2, ...]$$$

B = $$$[3, 4, 5, 6, 3, 4, ...]$$$

For the first test case, the following cycles (of size 4) are also accepted:

$$$[1, 4, 2, 5]$$$

$$$[3, 2, 4, 1]$$$

the graph for the first test casethe graph for the second test case

D. Black Nodes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You will be given a tree consisting of $$$n$$$ nodes, rooted at node 1. Each node can be white or black. Initially, all of the nodes are white. Also, you will be given $$$q$$$ queries of the form ($$$x_i$$$).

For each query, you have to toggle the color of the $$$x_i$$$-th node, (i.e. if it is black, it becomes white and vice versa), and then report the following value:

what is the maximum number of black nodes you can choose where no chosen node is an ancestor$$$^{\text{∗}}$$$ of another chosen one?

$$$^{\text{∗}}$$$In a rooted tree, a node $$$x$$$ is an ancestor of a node $$$y$$$ if and only if $$$x$$$ lies on the path from the root to $$$y$$$.

Input

Each test consists of multiple test cases. The first line contains a single integer $$$T$$$ $$$(1 \le T \le 10^3)$$$ — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$q$$$ $$$(2 \le n, q \le 10^5)$$$ — the size of the tree and the number of queries.

The second line of each test case contains $$$n - 1$$$ integers $$$p_2, \ldots, p_n$$$ $$$(1 \le p_i \le n)$$$ — the parent of node $$$i$$$.

Each of the next $$$q$$$ lines contains an integer $$$x_i$$$ $$$(1 \le x_i \le n)$$$ — representing the $$$i$$$-th query.

It is guaranteed that the given set of edges forms a tree.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$ and the sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each query, output the required value.

Example
Input
1
5 5
1 1 3 3
4
5
3
2
4
Output
1
2
2
3
2

E. Eating The Tree
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a tree with $$$n$$$ nodes. Each node $$$i$$$ has an initial value $$$A_i$$$.

You can perform a special eat operation. In this operation, you select two nodes, $$$u$$$ and $$$v$$$, that are directly connected by an edge. Node $$$u$$$ can eat node $$$v$$$ only if both of the following conditions are met:

  1. The value of $$$u$$$ is strictly greater than the value of $$$v$$$ (i.e., $$$A_u \gt A_v$$$).
  2. Node $$$v$$$ is a leaf $$$^{\text{∗}}$$$ in the current state of the tree.

When $$$u$$$ eats $$$v$$$, node $$$v$$$ and the edge connecting them are removed from the tree. The value of node $$$u$$$ is then updated by absorbing $$$v$$$'s value: $$$A_u = A_u + A_v$$$.

Your task is to determine if there exists a sequence of eat operations that results in the tree being reduced to a single node. If it is possible, give any possible sequence.

$$$^{\text{∗}}$$$A leaf is a node that has exactly one edge.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ $$$(1 \le T \le 10^4)$$$. The description of the test cases follows.

The first line contains a single integer $$$N$$$ ($$$2 \le n \le 2*10^5$$$).

The second line contains $$$n$$$ space-separated integers $$$A_1, A_2, \dots, A_n$$$ ($$$1 \le A_i \le 10^9$$$), the initial values of the nodes.

The next $$$n-1$$$ lines each contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n, u \ne v$$$), describing an edge between node $$$u$$$ and node $$$v$$$ . It is guaranteed that these edges form a tree and that sum of n over all testcases doesn't exceed $$$2*10^5$$$.

Output

If it's possible to reduce the tree to a single node, first print Yes. Then, print the $$$n-1$$$ operations that achieve this. Each operation should be printed on a new line as two space-separated integers u v, where node u eats node v.

If it's impossible, print No.

Example
Input
4
5
3 9 1 2 2
4 5
4 3
1 4
2 3
5
6 6 2 8 1
2 3
2 1
2 5
4 1
3
5 6 2
3 2
2 1
2
7 3
1 2
Output
No
No
Yes
2 3
2 1
Yes
1 2

F. A Problem You Will Hate More Than Yourself 2
time limit per test
4 s
memory limit per test
1024 megabytes
input
standard input
output
standard output

Whoever tries to solve this problem will either achieve great honor or face terrible failure!

You are given three integers $$$n$$$, $$$x$$$, and $$$y$$$, along with two arrays $$$a$$$ and $$$b$$$, each of length $$$n$$$.

You need to process $$$n$$$ turns. During the $$$i$$$-th turn, you must perform exactly one of the following actions:

  • Increase $$$x$$$ by $$$a_i$$$.
  • Increase $$$y$$$ by $$$a_i$$$.
  • Add $$$x \cdot y \cdot b_i$$$ to your score.

Your initial score is $$$0$$$. Determine the maximum score you can achieve after completing all $$$n$$$ turns.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \leq T \leq 10^3$$$). The description of the test cases follows.

The first line of each test case contains three integers $$$n$$$, $$$x$$$, and $$$y$$$ ($$$1 \leq n, x, y \leq 2*10^3$$$).

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2$$$), representing the array $$$a$$$.

The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \leq b_i \leq 10^6$$$), representing the array $$$b$$$.

It is guaranteed that the sum of $$$n^2$$$ across all test cases does not exceed $$$4 \cdot 10^6$$$.

Output

For each test case, output in a single line the maximum score you can get.

Example
Input
3
5 1 1
1 1 1 1 1
5 4 3 2 1
4 1 4
1 2 2 2
2 2 2 4
4 2 1
2 1 2 1
9 9 1 5
Output
24
100
114
Note

In the first test case, you can achieve a score of $$$24$$$ as follows:

  1. Increase $$$x$$$ by $$$1$$$.
  2. Increase $$$y$$$ by $$$1$$$.
  3. Add $$$2 \cdot 2 \cdot 3 = 12$$$ to your score.
  4. Add $$$2 \cdot 2 \cdot 2 = 8$$$ to your score.
  5. Add $$$2 \cdot 2 \cdot 1 = 4$$$ to your score.

It can be proven that $$$24$$$ is the maximum score you can achieve.

In the second test case, you can achieve a score of $$$100$$$ as follows:

  1. Increase $$$y$$$ by $$$1$$$.
  2. Increase $$$x$$$ by $$$2$$$.
  3. Increase $$$x$$$ by $$$2$$$.
  4. Add $$$5 \cdot 5 \cdot 4 = 100$$$ to your score.

G. Grid Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two grids of size $$$N \times M$$$, let's call them the target grid and your grid. The cells in both grids can be in one of two states: 'on' or 'off'. Initially, all cells in your grid are 'off', while the target grid has a specific configuration of 'on' and 'off' cells.

Your goal is to make your grid identical to the target grid by using a specific operation. The operation consists of three steps:

  1. Choose a cell at row $$$r$$$ and column $$$c$$$ in your grid.
  2. Flip the state of the chosen cell (if it's 'on', it becomes 'off', and if it's 'off', it becomes 'on').
  3. Simultaneously, every other row $$$i$$$ (where $$$i \ne r$$$) is cyclically shifted one position to the right. For example, a row [c1, c2, c3, c4] would become [c4, c1, c2, c3].

You need to find and print any valid sequence with minimum number of operations that transforms your initially off-state grid into the target grid.

Input

Each test consists of multiple test cases. The first line contains a single integer $$$T$$$ $$$(1 \le T \le 10^3)$$$ — the number of test cases. The description of the test cases follows.

The first line of each testcase contains two integers $$$N$$$ and $$$M$$$ ($$$1 \le N, M \le 1000$$$), the number of rows and columns in the grids.

The next $$$N$$$ lines of each testcase each contain a string of $$$M$$$ characters, representing the target grid. The character '1' denotes an 'on' cell, and '0' denotes an 'off' cell.

It's guaranteed that sum of n overall testcases doesn't exceed 1000 and sum of m doesn't exceed 1000.

Output

For each testcase, On the first line, print a single integer $$$K$$$, the minimum number of operations.

On the next $$$K$$$ lines, print two space-separated integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le N$$$, $$$1 \le c \le M$$$), representing the 1-based coordinates of a cell to perform the operation on. The total number of operations must not exceed $$$N \times M$$$.

Example
Input
2
1 1
0
4 2
00
11
01
01
Output
0
4
2 1
2 2
3 1
4 2

H. Sortable Grid
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a binary grid of size $$$N \times M$$$ (containing only '0's and '1's). You have a special ability: for any column, you can swap any two elements within that column. This means you can arrange the '0's and '1's in any column in any order you like, but you cannot move elements between different columns.

A grid is considered row-sorted if every row is sorted in non-decreasing order (i.e., all '0's appear before all '1's).

You will be given $$$Q$$$ queries. Each query consists of a cell $$$(r, c)$$$. For each query, you must first flip the value in cell $$$(r, c)$$$ of the current grid (a '0' becomes a '1', and a '1' becomes a '0'). This change is permanent and carries over to subsequent queries. After each flip, you must determine if the resulting grid can be made row-sorted using your column-swapping ability.

Input

Each test consists of multiple test cases. The first line contains a single integer $$$T$$$ $$$(1 \le T \le 10^5)$$$ — the number of test cases. The description of the test cases follows.

The first line of each test case contains integers $$$N, M,$$$ and $$$Q$$$ ($$$1 \le N, M$$$, $$$1 \le N \times M \le 10^5$$$, $$$1 \le Q \le 10^5$$$).

The next $$$N$$$ lines of each testcase each contain a string of $$$M$$$ characters ('0' or '1'), representing the initial grid.

The next $$$Q$$$ lines each contain two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le N$$$, $$$1 \le c \le M$$$), representi ng the coordinates of the cell to flip for that query. It's guaranteed that sum of N * M overall testcases doesn't exceed $$$10^5$$$ and sum of Q doesn't exceed $$$10^5$$$

Output

For each testcase, For each of the $$$Q$$$ queries, print Yes on a new line if the grid can be made row-sorted after the flip, and No otherwise.

Example
Input
5
5 2 3
11
11
01
00
11
3 1
4 2
4 1
3 7 2
0101001
0111111
1011100
1 4
1 6
2 2 4
11
01
2 2
2 1
1 1
1 1
3 4 1
1110
1110
1100
3 3
1 1 2
0
1 1
1 1
Output
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
No
Yes
Yes

I. Largest Divisible by Nine
time limit per test
1 second
memory limit per test
512 MB
input
standard input
output
standard output

Shaban loves divisibility by 9, he has a number x with $$$n$$$ digits and he wants to transform it to the maximum number that is divisible by 9 by performing exactly $$$k$$$ of the following operation:

Each operation consists of choosing any single digit of x and doing one of the following:

  • Increase the digit by 1, if its value is less than 9.
  • Decrease the digit by 1, if its value is greater than 0.

Shaban will do exactly $$$k$$$ operations to transform the initial number into a new $$$n$$$-digit number that satisfies two conditions:

  1. The new number must be divisible by 9.
  2. The new number must be the largest possible.

The resulting number can have leading zeros. If it's impossible to create such a number, you should print -1.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 10^5$$$), The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le k \le 10^7$$$), representing the number of digits in the number and the number of operations, respectively.

The second line of each test case contains a string of $$$n$$$ digits, representing the initial number. The string can have leading zeros.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each test case, print a single line containing the resulting $$$n$$$-digit number that is as large as possible and divisible by 9. If no such number can be formed within $$$k$$$ operations, print -1.

Example
Input
7
2 4
70
1 2
3
2 3
30
2 2
18
10 16
1234567890
11 5
31599146004
10 100
1356849840
Output
90
-1
00
27
9234567810
71599146003
9999999999
Note

First Test Case:

  • Start with the number 70.
  • Add 1 to the first digit: $$$70 \to 80$$$
  • Add 1 to the first digit again: $$$80 \to 90$$$
  • Add 1 to the second digit: $$$90 \to 91$$$
  • Subtract 1 from the second digit: $$$91 \to 90$$$

The maximum number you can obtain is $$$90$$$, and it is divisible by 9.

Second Test Case:

No matter how you change the digits, the number will never become divisible by 9. so the answer is $$$-1$$$.

Third Test Case:

  • Start with the number 30.
  • Subtract 1 from the first digit three times: $$$30 \to 20 \to 10 \to 00$$$
  • The resulting number is $$$00$$$, which is divisible by 9.

Fourth Test Case:

  • Start with the number 18.
  • Subtract 1 from the second digit one time: $$$18 \to 17$$$
  • add 1 to the first digit one time: $$$17 \to 27$$$
  • The resulting number is $$$27$$$, which is divisible by 9 and is the largest number you can have.

J. Pixel Canvas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are an artist working on an infinitely large 2D pixel art canvas. Your goal is to fill a specific rectangular area with color, using the minimum number of new pixels.

The rectangular area to be filled is defined by its top-left corner $$$(X_1, Y_1)$$$ and its bottom-right corner $$$(X_2, Y_2)$$$, inclusive. On this canvas, the y-coordinates increase upwards.

To start, you are given $$$n$$$ pixels that are already colored at positions $$$(x_i, y_i)$$$.

You have two ways to color a new pixel:

  1. Ground Operation: You can color any pixel on the "ground" row, which is the set of all cells with a y-coordinate of 1.
  2. Spread Operation: You can color a pixel that is adjacent (shares a side) to a pixel that is already colored.

Your task is to find the minimum number of new pixels you must color to ensure the entire rectangular area from $$$(X_1, Y_1)$$$ to $$$(X_2, Y_2)$$$ is completely filled.

Input

The first line contains a single integer $$$n$$$ ($$$0 \le n \le 10^5$$$), the number of initially colored pixels.

The second line contains four integers $$$X_1, Y_1, X_2, Y_2$$$ ($$$1 \le X_1 \le X_2 \le 10^9$$$, $$$1 \le Y_2 \le Y_1 \le 10^9$$$), defining the target rectangle.

The next $$$n$$$ lines each contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le 10^9$$$), the coordinates of an initially colored pixel.

Output

Print a single integer: the minimum number of new pixels required to fill the target rectangle.

Examples
Input
3
3 6 6 4
5 5
3 2
8 5
Output
11
Input
0
4 4 4 4
Output
4
Input
1
3 4 4 3
3 2
Output
4
Input
1
3 6 6 4
7 5
Output
12

K. An Easy Math Problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Baran wants to ensure that the problem Shaban prepared for the LCPC contest is approachable for the students. To make it more accessible, he has simplified the task as follows:

Given a very large number $$$n$$$ (where $$$0 \leq n \leq 10^{10^5}$$$), determine if $$$n$$$ is divisible by 9.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$T (1 \le T \le 10^4)$$$. The description of the test cases follows.

The first and only line of each test case contains one integer $$$n$$$ $$$(0 \le n \le 10^{10^5})$$$ — the given large number.

It's guaranteed that the sum of the number of digits for all the test cases won't exceed $$$10^{5}$$$.

Output

Print Yes if the number is divisible by $$$9$$$; otherwise, print No.

Example
Input
10
333
234
18
09
666
8
11
116
568
71
Output
Yes
Yes
Yes
Yes
Yes
No
No
No
No
No

L. Dynamic String Array
time limit per test
1 second
memory limit per test
256 MB
input
standard input
output
standard output

You are given an empty array of strings, let's call it $$$A$$$. You need to process $$$n$$$ queries of three different types.

The queries are as follows:

  • 1 S: Add the string $$$S$$$ to the array $$$A$$$.
  • 2 c: Append the character $$$c$$$ to the end of every string currently present in the array $$$A$$$.
  • 3 x: Check if the string $$$x$$$ exists in the array $$$A$$$. For this query, you must output "Yes" or "No".

Your task is to handle these queries and provide the correct output for all type 3 queries.

Input

The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of queries.

The following $$$n$$$ lines each describe a query. The format for each query is one of the following:

  • 1 S: where $$$S$$$ is a string consisting of lowercase English letters ($$$1 \le |S| \le 10^6$$$).
  • 2 c: where $$$c$$$ is a single lowercase English letter.
  • 3 x: where $$$x$$$ is a string consisting of lowercase English letters ($$$1 \le |x| \le 10^6$$$).

It is guaranteed that the sum of lengths of all strings $$$S$$$ in type 1 queries and all strings $$$x$$$ in type 3 queries does not exceed $$$10^6$$$.

Note: it is guaranteed that the first query is from type one.

Output

For each query of type 3, print "Yes" on a new line if the string $$$x$$$ is found in the array $$$A$$$. Otherwise, print "No".

Example
Input
5
1 abc
3 abc
2 c
3 abc
3 abcc
Output
Yes
No
Yes
Note

Let $$$A$$$ be the array of strings. We will trace its state through each query to understand the output.

  1. Initial State: The array $$$A$$$ is empty. $$$$$$ A = [ \quad ] $$$$$$

  2. Query 1: 1 abc This query adds the string "abc" to the array $$$A$$$. $$$$$$ A = [ \text{"abc"} ] $$$$$$

  3. Query 2: 3 abc This query checks if the string "abc" exists in $$$A$$$. It does. $$$$$$ \rightarrow \textbf{Output: Yes} $$$$$$

  4. Query 3: 2 c This query appends the character 'c' to every string currently in $$$A$$$. The string "abc" is modified to become "abcc". $$$$$$ A = [ \text{"abcc"} ] $$$$$$

  5. Query 4: 3 abc This query checks for the string "abc" in $$$A$$$. The array no longer contains "abc"; it only contains "abcc". $$$$$$ \rightarrow \textbf{Output: No} $$$$$$

  6. Query 5: 3 abcc This query checks for the string "abcc" in $$$A$$$. This string is present. $$$$$$ \rightarrow \textbf{Output: Yes} $$$$$$

M. Rob And Lie
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is the conclusion of the story from the problem "Codeforces Round (1025) A. It's Time to Duel."

At the end of the Yu-Gi-Oh! tournament, it was time to give out the prizes. The biggest prize was a rare copy of the card "Blue Eyes White Dragon."

But then, something bad happened: someone stole the card. This made Mouf, the person in charge of the tournament, very angry. He thought that everyone in the tournament knew who the thief was, but they were too scared to say anything.

To find out the truth, Mouf came up with a plan. He lined up all the $$$n$$$ players and gave each one a number from $$$1$$$ to $$$n$$$. Then he asked them, "What is the difference between your number and the thief's number?" This question created a list called $$$a$$$, where $$$a_i$$$ was the answer from player number $$$i$$$.

However, exactly one player lied about their distance from the thief. Now, Mouf needs your help to figure out who the thief is or to declare that it's impossible to find out.

Note that the liar may be the one who stole the prize.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$T (1 \le T \le 10^4)$$$. The description of the test cases follows.

The first line of each test case contains one integer $$$n$$$ $$$(2 \le n \le 10^5)$$$ — the number of players in the tournament.

The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,…,a_n$$$ $$$(0 \le a_i \le n-1)$$$ — denoting the answer from player number $$$i$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$, and that each test case contains exactly 1 liar.

Output

For each test case output in a single line the thief number or $$$-1$$$ if it is impossible to find out the thief.

Example
Input
6
2
1 1
3
2 0 0
3
0 1 0
4
3 1 2 3
4
1 0 1 0
5
1 3 1 2 3
Output
-1
3
-1
1
2
2