from sys import stdin, stdout
import sys
import os
#all = ""
N = 10004
drop_ary = [0 for i in range(N)]
xor_ary = [0 for i in range(N)]
for i in range(N) :
x = i
if x%4 == 0 : xor = x
if x%2 :
if x%4 == 1: xor = 1
else: xor = 0
drop = x
else :
if x%4 == 2: xor = x + 1
else: xor = x
drop = 0
while x > 0 :
x >>= 1
drop = (drop << 1) + 1
drop_ary[i] = drop
xor_ary[i] = xor
N = int(input())
#xx = [int(stdin.readline()) for i in range(N)]
for i in range(N) :
if i > 80000 :
exit(0)
x = int(input())
os.write(1, bytes(str(xor_ary[x]) + " " + str(drop_ary[x]) + "\n", 'ascii'))
# continue
# x = xx[i]
# if x%4 == 0 : xor = x
# if x%2 :
# if x%4 == 1: xor = 1
# else: xor = 0
# drop = x
# else :
# if x%4 == 2: xor = x + 1
# else: xor = x
# drop = 0
# while x > 0 :
# x >>= 1
# drop = (drop << 1) + 1
# os.write(1, bytes(str(xor) + " " + str(drop) + "\n", 'ascii'))
# sys.stdout.write(str(xor) + " " + str(drop) + "\n")
# print(xor, drop)
#sys.stdout.write(all)
#os.write(1, bytes(all, 'ascii'))
#print(17, 17)