Easy_Training
A. Rook
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As you probably know, chess is a game that is played on a board with 64 squares arranged in an $$$8\times 8$$$ grid. Columns of this board are labeled with letters from a to h, and rows are labeled with digits from 1 to 8. Each square is described by the row and column it belongs to.

The rook is a piece in the game of chess. During its turn, it may move any non-zero number of squares horizontally or vertically. Your task is to find all possible moves for a rook on an empty chessboard.

Input

The first line of input contains single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of test cases. The descriptions of test cases follow.

Each test case contains one string of two characters, description of the square where rook is positioned. The first character is a letter from a to h, the label of column, and the second character is a digit from 1 to 8, the label of row.

The same position may occur in more than one test case.

Output

For each test case, output descriptions of all squares where the rook can move, in the same format as in the input.

You can output squares in any order per test case.

Example
Input
1
d5
Output
d1
d2
b5
g5
h5
d3
e5
f5
d8
a5
d6
d7
c5
d4

B. Good Kid
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Slavic is preparing a present for a friend's birthday. He has an array $$$a$$$ of $$$n$$$ digits and the present will be the product of all these digits. Because Slavic is a good kid who wants to make the biggest product possible, he wants to add $$$1$$$ to exactly one of his digits.

What is the maximum product Slavic can make?

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 9$$$) — the number of digits.

The second line of each test case contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$0 \leq a_i \leq 9$$$) — the digits in the array.

Output

For each test case, output a single integer — the maximum product Slavic can make, by adding $$$1$$$ to exactly one of his digits.

Example
Input
4
4
2 2 1 2
3
0 1 2
5
4 3 2 3 4
9
9 9 9 9 9 9 9 9 9
Output
16
2
432
430467210

C. Word on the Paper
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

On an $$$8 \times 8$$$ grid of dots, a word consisting of lowercase Latin letters is written vertically in one column, from top to bottom. What is it?

Input

The input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.

Each test case consists of $$$8$$$ lines, each containing $$$8$$$ characters. Each character in the grid is either $$$\texttt{.}$$$ (representing a dot) or a lowercase Latin letter ($$$\texttt{a}$$$–$$$\texttt{z}$$$).

The word lies entirely in a single column and is continuous from the beginning to the ending (without gaps). See the sample input for better understanding.

Output

For each test case, output a single line containing the word made up of lowercase Latin letters ($$$\texttt{a}$$$–$$$\texttt{z}$$$) that is written vertically in one column from top to bottom.

Example
Input
5
........
........
........
........
...i....
........
........
........
........
.l......
.o......
.s......
.t......
........
........
........
........
........
........
........
......t.
......h.
......e.
........
........
........
........
........
.......g
.......a
.......m
.......e
a.......
a.......
a.......
a.......
a.......
a.......
a.......
a.......
Output
i
lost
the
game
aaaaaaaa

D. Gift Carpet
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, Tema and Vika celebrated Family Day. Their friend Arina gave them a carpet, which can be represented as an $$$n \cdot m$$$ table of lowercase Latin letters.

Vika hasn't seen the gift yet, but Tema knows what kind of carpets she likes. Vika will like the carpet if she can read her name on. She reads column by column from left to right and chooses one or zero letters from current column.

Formally, the girl will like the carpet if it is possible to select four distinct columns in order from left to right such that the first column contains "v", the second one contains "i", the third one contains "k", and the fourth one contains "a".

Help Tema understand in advance whether Vika will like Arina's gift.

Input

Each test consists of multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 20$$$) — the sizes of the carpet.

The next $$$n$$$ lines contain $$$m$$$ lowercase Latin letters each, describing the given carpet.

Output

For each set of input data, output "YES" if Vika will like the carpet, otherwise output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

Example
Input
5
1 4
vika
3 3
bad
car
pet
4 4
vvvv
iiii
kkkk
aaaa
4 4
vkak
iiai
avvk
viaa
4 7
vbickda
vbickda
vbickda
vbickda
Output
YES
NO
YES
NO
YES
Note

In the first sample, Vika can read her name from left to right.

In the second sample, Vika cannot read the character "v", so she will not like the carpet.

E. Game with Integers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya and Vova are playing a game. Players are given an integer $$$n$$$. On their turn, the player can add $$$1$$$ to the current integer or subtract $$$1$$$. The players take turns; Vanya starts. If after Vanya's move the integer is divisible by $$$3$$$, then he wins. If $$$10$$$ moves have passed and Vanya has not won, then Vova wins.

Write a program that, based on the integer $$$n$$$, determines who will win if both players play optimally.

Input

The first line contains the integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases.

The single line of each test case contains the integer $$$n$$$ ($$$1 \leq n \leq 1000$$$).

Output

For each test case, print "First" without quotes if Vanya wins, and "Second" without quotes if Vova wins.

Example
Input
6
1
3
5
100
999
1000
Output
First
Second
First
First
Second
First

F. Morning
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a four-digit pin code consisting of digits from $$$0$$$ to $$$9$$$ that needs to be entered. Initially, the cursor points to the digit $$$1$$$. In one second, you can perform exactly one of the following two actions:

  • Press the cursor to display the current digit,
  • Move the cursor to any adjacent digit.

The image above shows the device you are using to enter the pin code. For example, for the digit $$$5$$$, the adjacent digits are $$$4$$$ and $$$6$$$, and for the digit $$$0$$$, there is only one adjacent digit, $$$9$$$.

Determine the minimum number of seconds required to enter the given four-digit pin code.

Input

Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) - the number of the test cases. This is followed by their description.

The single line of each test case describes the pin code as a string of length $$$4$$$, consisting of digits from $$$0$$$ to $$$9$$$.

Output

For each test case, output the minimum number of seconds required to enter the given pin code.

Example
Input
10
1111
1236
1010
1920
9273
0000
7492
8543
0294
8361
Output
4
9
31
27
28
13
25
16
33
24
Note

In the first test case, the cursor needs to be pressed $$$4$$$ times.

In the second test case, it can be done in $$$9$$$ seconds as follows:

  • Press the cursor.
  • Move the cursor to the digit $$$2$$$.
  • Press the cursor.
  • Move the cursor to the digit $$$3$$$.
  • Press the cursor.
  • Move the cursor to the digit $$$4$$$.
  • Move the cursor to the digit $$$5$$$.
  • Move the cursor to the digit $$$6$$$.
  • Press the cursor.