def xor(n): if n < 0: return 0 mod = n % 4 if mod == 0: return n elif mod == 1: return 1 elif mod == 2: return n + 1 else: return 0 def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 res = 0 for _ in range(N): K = int(input[ptr]) L = int(input[ptr+1]) D = int(input[ptr+2]) ptr += 3 s = 1 << D lower = L % s a = (L - lower) // s count = K m = a + count - 1 if a > 0: xor_a_minus_1 = xor(a - 1) else: xor_a_minus_1 = 0 xor_m_val = xor(m) xor_high = xor_a_minus_1 ^ xor_m_val higher_part = s * xor_high if count % 2 == 1: lower_part = lower else: lower_part = 0 current_xor = lower_part ^ higher_part res ^= current_xor print(res) if __name__ == "__main__": main()