#K50657. Minimum Possible Maximum Bitwise AND Value

    ID: 28913 Type: Default 1000ms 256MiB

Minimum Possible Maximum Bitwise AND Value

Minimum Possible Maximum Bitwise AND Value

You are given T test cases. In each test case, two positive integers n and k are provided.

For each test case, consider an array whose elements can be chosen arbitrarily. Define the value of a non-empty subset as the bitwise AND of all its elements. Let M be the maximum value among all non-empty subsets of the array. Your task is to determine the minimum possible value of M by choosing an appropriate array.

Observation:

  • If n = 1, the array consists of a single element and the only subset is the array itself, so the answer is k.
  • If n > 1, it is always possible to include an element with value 0 in the array. Since 0 ∧ x = 0 for any x, the maximum bitwise AND over all subsets can be forced to be 0. Therefore, the answer is 0.

Formally, the answer for a test case is given by:

$$\text{{answer}} = \begin{cases} k, & \text{if } n = 1 \\ 0, & \text{if } n > 1 \end{cases} $$

Print the answer for each test case on a separate line.

inputFormat

The input is given via standard input and has the following format:

T
n1 k1
n2 k2
... 
nT kT

Here:

  • T is the number of test cases.
  • Each test case contains two space-separated integers n and k.

outputFormat

For each test case, output a single integer on a separate line representing the minimum possible maximum value of the bitwise AND of all non-empty subsets of an array chosen according to the conditions described above.

## sample
4
3 5
2 8
6 10
1 7
0

0 0 7

</p>