#spagetti
def ListToInt2(InputList):
ReturnValue = 0
for i, value in enumerate(InputList):
if value == 1:
ReturnValue += 2**(len(InputList)-i-1)
return ReturnValue
def ListToInt(InputList):
ReturnValue = 0
for value in InputList:
ReturnValue += ReturnValue
if value == 1:
ReturnValue += 1
return ReturnValue
b = 30
N = int(input())
for i in range(N):
RangeTop = int(input())
osszeg = 0
OsszeszamlaloLista = [0 for i in range(b)]
for i in range(RangeTop+1):
osszeg ^= i
for index, j in enumerate(str(bin(i)[2:]).zfill(b)):
if j == "1":
OsszeszamlaloLista[index] += 1
KeresettSzamBinarisban = [0 for i in range(b)]
for i, value in enumerate(OsszeszamlaloLista):
if int(value) % 2 == 0 and value != 0:
KeresettSzamBinarisban[i] = 1
if ListToInt(KeresettSzamBinarisban) > RangeTop:
KeresettSzamBinarisban[i] -=1
print(osszeg, osszeg^ListToInt(KeresettSzamBinarisban))