Under construction

Still being built. Things may change

Perfect Triples

Time limit2sMemory limit1024 MB

Summary
Given n up to 1e16, find the n-th element of a sequence built by repeatedly appending the lexicographically smallest unused triple with XOR zero.
Level

Hard8 of 10

Topics
Bit manipulation, Math
Solved
No attempts yet

Problem

Consider the infinite sequence ss of positive integers, created by repeating the following steps:

  1. Find the lexicographically smallest triple of positive integers (a,b,c)(a, b, c) such that

    • a⊕b⊕c=0a \oplus b \oplus c = 0, where ⊕\oplus denotes the bitwise XOR operation.
    • aa, bb, cc are not in ss.

    A triple (a1,b1,c1)(a_1, b_1, c_1) is lexicographically smaller than (a2,b2,c2)(a_2, b_2, c_2) if the sequence [a1,b1,c1][a_1, b_1, c_1] is lexicographically smaller than [a2,b2,c2][a_2, b_2, c_2].

  2. Append aa, bb, cc to ss in this order.

  3. Go back to the first step.

You have integer nn. Find the nn-th element of ss.

You have to answer tt independent test cases.

A sequence aa is lexicographically smaller than a sequence bb if, at the first position where aa and bb differ, the element of aa is smaller than the corresponding element of bb.

Input

The first line contains a single integer tt (1≤t≤1051 \le t \le 10^5), the number of test cases.

Each of the next tt lines contains a single integer nn (1≤n≤10161 \le n \le 10^{16}), the position of the element you want to know.

Output

For each test case, output the answer on its own line.

Hint

The first elements of ss are 1,2,3,4,8,12,5,10,15,…1, 2, 3, 4, 8, 12, 5, 10, 15, \dots

Examples1

  1. Example 1

    Input
    9
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    Expected output
    1
    2
    3
    4
    8
    12
    5
    10
    15