Comments

Unlike other more complicated solutions, my approach to the C problem is simple:

def solve():
    b, c, d = map(int, input().split())
    a = (b | d) - (c & d)
    print(a if (b | a) - (c & a) == d else -1)

t = int(input())
for _ in range(t): solve()

Perhaps it's time to implement AI-based monitoring of user actions to ensure fair contests.