from sys import stdin, stdout
import sys
import os
def main() :
N = 10000
max = 1
cnt = 1
drop0 = 3
xor_ary = [0 for i in range(N+1)]
drop_ary = [0 for i in range(N+1)]
for x in range(1,N) :
if x%4 == 0 : xor = x
if x%4 == 1 : xor = 1
if x%4 == 2 : xor = x + 1
if x%4 == 3 : xor = 0
if x%2:
drop = x
else:
drop = drop0
cnt += 1
if cnt > max :
cnt = 1
max += max
drop0 = drop0 + drop0 + 1
xor_ary[x] = xor
drop_ary[x] = drop
#print(x, xor, drop)
N = int(input())
for i in range(N) :
if i > 110000 :
exit(0)
x = int(input())
os.write(1, bytes(str(xor_ary[x]) + " " + str(drop_ary[x]) + "\n", 'ascii'))
# if x%4 == 0 : xor = x
# if x%4 == 1 : xor = 1
# if x%4 == 2 : xor = x + 1
# if x%4 == 3 : xor = 0
# if x%2 :
# drop = x
# else :
# drop = x
# while x != 0 :
# x >>= 1
# drop |= x
# os.write(1, bytes(str(xor) + " " + str(drop) + "\n", 'ascii'))
# print(xor, drop)
main()