import sys def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n = II() x = 0 for _ in range(n): k, l, d = LI() d2 = 1 << d for i in range(k): x ^= l+d2*i print(x)