TheForces Round #31 (Div2.9-Forces)
A. King Supremacy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a chessboard containing $$$n$$$ rows and $$$m$$$ columns. Cell at the $$$i^{th}$$$ row and $$$j^{th}$$$ column is denoted as $$$(i,j)$$$. Cell $$$(i,j)$$$ is colored white if $$$(i+j)$$$ is even; otherwise, it is colored black.

Your task is to place the maximum kings on white cells such that no two kings attack each other.

Two kings will attack each other if their cells are adjacent by edge or corner.

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 testcase contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 100$$$).

Output

For each test case, print a single integer — the maximum number of kings placed on the given chessboard which satisfies the given condition.

Example
Input
6
2 3
6 1
4 4
7 8
6 7
4 9
Output
2
3
4
16
12
10

B. Circular Cone
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Zogbi is playing a video game, in which there is a circle divided into $$$n$$$ equal sectors, and initially each sector has a cone in it. She wins the game if she moves all the cones to any one specific sector in the minimum number of operations.

In one operation, she can select any two distinct cones and must move both of them independently to any one of their adjacent sectors from their current sector.

Note: two sectors are adjacent if they share a side in circular order.

For example, consider the case $$$n = 4$$$, as shown below. In each operation, she moves the two cones shown by red arrows to an adjacent sector. She makes exactly two operations to move all cones to one same sector. And it can be shown that one cannot do it in less than $$$2$$$ operations.

n = 4, operations are shown by red arrows.

Find the minimum number of operations. If it is impossible to move all cones to the same sector, output $$$-1$$$ instead.

Input

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

The first line of each test case contains only one positive integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$), representing the number of sectors (so the cones).

Additionally, the sum of n over all the test cases doesn't exceed $$$2\cdot10^5$$$.

Output

For each test case, output a single line containing an integer  — the minimum number of operations to move all cones to one same sector. If it is impossible to move all cones to the same sector, then output $$$-1$$$ instead.

Example
Input
7
1
2
3
4
5
8
12
Output
0
-1
1
2
3
8
18
Note

The fourth test case is explained with a figure in the problem statement.

C. Super Pair
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You will be given a tree containing $$$n$$$ nodes. An unordered pair $$$(u,v)$$$ is called a Super Pair if it satisfies the following conditions:

  1. $$$u≠v$$$;
  2. Initially, there will be no edge between node $$$u$$$ and node $$$v$$$;
  3. If we add an edge between $$$u$$$ and $$$v$$$, there will be exactly one shortest path between every pair of nodes. Note that we don't add this edge in the tree actually.

Your task is to calculate the number of Super Pairs.

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 testcase contains a single integer $$$n$$$ $$$(2 \le n \le 10^{5})$$$ — the number of nodes in the given tree.

The next $$$n-1$$$ lines contain two integers $$$u,v$$$ $$$(1 \le u,v \le n, u≠v)$$$ — there is an edge connecting $$$u$$$ and $$$v$$$.

It is guaranteed that the sum of $$$n$$$ over all testcases doesn't exceed $$$10^{5}$$$.

Output

For each testcase, print a single integer — the number of Super Pairs.

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

D. Permutational Mex
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pritesh had a permutation $$$p$$$ of length $$$n$$$. He took all the prefixes $$$[p_1, p_2, \dots, p_i]$$$ ($$$1\leq i\leq n$$$) of the permutation $$$p$$$ and calculated the $$$\operatorname{MEX}$$$ (minimal excluded element) of each prefix. Unfortunately, he forgot the permutation but remembers the sum $$$S$$$ of all the MEX values. Can you help him find the permutation $$$p$$$?

If there are multiple solutions, print any of them. If there is no solution, print a single integer $$$-1$$$.

The $$$\operatorname{MEX}$$$ of a collection of integers $$$c_1, c_2, \ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$.

A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$0$$$ to $$$n-1$$$ in arbitrary order. For example, $$$[2, 3, 1, 0, 4]$$$ is a permutation, but $$$[0, 1, 1]$$$ is not a permutation ($$$1$$$ appears twice in the array), and $$$[0, 2, 3]$$$ is also not a permutation ($$$n = 3$$$ but there is $$$3$$$ in the array).

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 $$$S$$$ ($$$1 \le n \le 3 \times 10^5$$$, $$$1 \le S \le 10^9$$$).

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

Output

For each test case, output the permutation $$$p$$$ of length $$$n$$$ such that the sum of the MEX of all prefixes equals $$$S$$$. If there are multiple solutions, print any of them. If there is no solution, print a single integer $$$-1$$$.

Example
Input
4
3 5
2 10
2 2
4 3
Output
0 2 1
-1
1 0 
-1
Note

For the first test case, $$$\operatorname{MEX}([0]) + \operatorname{MEX}([0, 2]) + \operatorname{MEX}([0, 2, 1]) = 1 + 1 + 3 = 5$$$.

For the second test case, it can be shown that no such permutation exists.

E. XOR Priority
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
"Did you know that the XOR symbol $$$(\oplus)$$$ is just the ADD symbol $$$(+)$$$ with a circle?"
— $$$LaTeX$$$, probably

You have $$$n$$$ integers $$$a_1,a_2,...,a_n$$$ written from left to right. For all integers $$$1 \leq i \lt n$$$, you can either put an XOR symbol ($$$\oplus$$$) or an ADD symbol ($$$+$$$) between $$$a_i$$$ and $$$a_{i+1}$$$ to form an expression. The cost of the expression formed is the alternative result of the expression itself. Find the sum of costs from all possible $$$2^{n-1}$$$ expressions. Since the sum of costs might be too large, find the sum modulo $$$998244353$$$.

The alternative result of an expression is the result of the expression if the XOR operation is done before any other operation. For example, the alternative result of $$$5 + 3 \oplus 5$$$ is $$$5 + 6 = 11$$$ since $$$3 \oplus 5 = 6$$$ and the XOR operation has to be done before the ADD operation.

Input

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

The first line for each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 5 \cdot 10^5$$$) — the number of integers inside the expression.

The second line for each test case contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$1 \leq a_i \lt 2^{29}$$$).

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

Output

For each test case, output a single integer — the sum of costs from all possible $$$2^{n-1}$$$ expressions, modulo $$$998244353$$$.

Example
Input
4
3
5 3 5
2
1012 1012
3
166374059 166374059 166374059
5
123456789 432101234 123454321 456787654 133769420
Output
38
2024
1
153140146
Note

Let $$$f(X)$$$ be the cost of the expression $$$X$$$.

For the first test case, there are $$$4$$$ expressions, which are $$$\{5 + 3 + 5\}, \{5 + 3 \oplus 5\}, \{5 \oplus 3 + 5\}, \{5 \oplus 3 \oplus 5\}$$$. The sum of costs is $$$f(\{5 + 3 + 5\}) + f(\{5 + 3 \oplus 5\}) + f(\{5 \oplus 3 + 5\}) + f(\{5 \oplus 3 \oplus 5\}) = 13 + 11 + 11 + 3 = 38$$$.

For the second test case, there are $$$2$$$ expressions, which are $$$\{1012 + 1012\}$$$ and $$$\{1012 \oplus 1012\}$$$.

F. Count via Construct
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This time Yugandhar came up with two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$ and is thinking of asking you to construct a binary matrix which has $$$n$$$ rows and $$$n$$$ columns, such that the following condition holds:

  1. Bitwise AND of all the numbers in the $$$i^{th}$$$ row of the constructed matrix will be equal to $$$a_{i}$$$ $$$(1 \le i \le n)$$$.
  2. Bitwise OR of all the numbers in the $$$i^{th}$$$ column of the constructed matrix will be equal to $$$b_{i}$$$ $$$(1 \le i \le n)$$$.

But Wuhudsm thinks it is boring to concentrate on a single thing. Hence, he asked you to calculate the number of different binary matrices of size $$$n$$$ rows and $$$n$$$ columns which you can construct to make the above conditions hold.

The number may be large so print it modulo $$$10^{9}+7$$$.

Input

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

The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the length of binary strings $$$a$$$ and $$$b$$$.

The second line of each testcase contains a binary string $$$a$$$ of length $$$n$$$.

The third line of each testcase contains a binary string $$$b$$$ of length $$$n$$$.

Output

For each test case, print a single integer — the number of different binary matrices modulo $$$10^{9}+7$$$.

Example
Input
5
2
00
11
2
01
11
3
001
111
3
010
110
4
0000
0101
Output
2
3
49
0
225
Note

In the first test case, all possible matrices are:

01
10

10
01

In the second test case, all possible matrices are:

00
11

01
11

10
11

G. Multiple Game
time limit per test
6 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice and Bob play a game on two positive integers $$$x$$$ and $$$y$$$. They take turns alternatively, with Alice making the first move. In a move, a player can subtract a multiple of one number from the other number. After the operation, both should remain non-negative. The first person to make the value of $$$x \cdot y$$$ equal to $$$0$$$ wins.

An example of the game on $$$x = 4$$$, $$$y = 14$$$:

  • Alice subtracts $$$8$$$ (a multiple of $$$x=4$$$) from $$$y = 14$$$. Now, $$$x = 4$$$ and $$$y = 6$$$;
  • Bob subtracts $$$4$$$ (a multiple of $$$x=4$$$) from $$$y = 6$$$. Now, $$$x = 4$$$ and $$$y = 2$$$;
  • Alice subtracts $$$4$$$ (a multiple of $$$y=2$$$) from $$$x = 4$$$. Now, $$$x = 0$$$ and $$$y = 2$$$. After that, Alice wins since $$$x \cdot y = 0$$$.

Given two positive integers $$$l$$$ and $$$r\ (l \le r)$$$. Your task is to find the number of ordered pairs $$$(x,y)$$$ such that $$$l \le x \le y \le r$$$ and Alice wins for these pairs.

Input

The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$).

For each test case, the only line contains two space-separated integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$).

Output

For each test case output a single number in a new line  — the number of ordered pairs for which Alice will win.

Example
Input
4
1 3
4 5
66 999
1 1000000
Output
5
2
247645
309017803391
Note

In the first test case, the ordered pairs for which Alice will win are $$$(1,1),(1,2),(1,3),(2,2)$$$ and $$$(3,3)$$$.

In the second test case, the ordered pairs for which Alice will win are $$$(4,4)$$$ and $$$(5,5)$$$.