#P11485. 「Cfz Round 5」Non-breath Oblige

    ID: 10797 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学贪心洛谷原创O2优化位运算洛谷月赛

「Cfz Round 5」Non-breath Oblige

Description

Given three integers n,s,tn, s, t, where 0s,t<2n0 \le s, t < 2^n.

You can perform several operations. In each operation, you can choose a non-negative integer xx and modify the value of ss to xx, subject to the following conditions:

  • It must satisfy x<2nx < 2^n;
  • It must satisfy sx=2n1s \cup x = 2^n - 1, where \cup denotes the bitwise OR operation;
  • The cost you need to pay is sxs \oplus x, where \oplus denotes the bitwise XOR operation.

You need to find the minimum sum of costs required to make s=ts = t.

Input Format

Each test contains multiple test cases.

The first line of input contains a positive integer TT, denoting the number of test cases.

Each test case is given in a following line, containing three integers n,s,tn, s, t.

Output Format

For each test case, output a single integer on a line, representing the minimum sum of costs required to make s=ts = t.

3
2 1 2
3 1 1
5 1 4
3
0
57

Hint

Sample Explanation #1

For the first test case, since 12=31 \cup 2 = 3, you can directly change the value of ss from 11 to 22, with a cost of 121 \oplus 2, which is 33. It can be proven that the minimum sum of costs required to make s=ts = t is 33.

For the second test case, no operation is needed to satisfy s=ts = t.

Constraints

For all test cases, it is guaranteed that:

  • 1T1001 \le T \le 100;
  • 1n301 \le n \le 30;
  • 0s,t<2n0 \le s, t < 2^n.

Subtasks are used in this task.

  • Subtask 0 (12 points): s=ts = t.
  • Subtask 1 (15 points): n=1n = 1.
  • Subtask 2 (20 points): s+t=2n1s + t = 2^n - 1.
  • Subtask 3 (10 points): t=2n1t = 2^n - 1.
  • Subtask 4 (18 points): t=0t = 0.
  • Subtask 5 (25 points): No further restrictions.