XORSUM#11837

XORSUM

1 second
256 megabytes
Hard

"Woooooo"

—TheFatRat - Arcadia

A function is defined as follows :

\displaystyle \begin{cases} f(1)=a \\ f(2)=b \\ f(x)=f(x-1) \oplus f(x-2)\\ \end{cases}

Here x \oplus y denotes the bitwise XOR operation of integers and .

You're given four integers , , , . Your task is to evaluate the sum of function values for each integer from to (inclusive).

More formally,

\displaystyle \left ( \sum_{x=l}^r f(x) \right ) = f(l)+f(l+1)+...+f(r)

Input

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

The only line of each test case contains four integers , , , (1 \le a,b \le 10^9) (1 \le l \le r \le 10^9).

Output

For each test case , output the required sum.

Please note ! that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

It can be shown that the answer for each test case doesn't exceed 2 \cdot 10^{18}

Examples

Example 1

Loading
Loading

Note

In the first test case, f(4)+f(5)+f(6)=1+3+2=6.

In the third test case, f(33)+f(34)=112+100=212.

In the fourth test case, f(3)+f(4)+f(5)=8+10+2=20

Scoring

  1. Subtask ( points): (a=b=l=r)

  2. Subtask ( points) : (l=r)

  3. Subtask ( points) : (a=b)

  4. Subtask ( points) : (1 \le \sum r-l+1 \le 5 \cdot 10^5)

  5. Subtask ( points) : (1 \le a,b,l,r \le 10^4)

  6. Subtask ( points) : No additional constraints.