Bob's OR Wish
Alice is holding a number a and Bob is holding a number b, both written in binary. A genie will
grant their wish the moment a OR b (bitwise OR) equals a wished-for number c — but the genie is
lazy, so Alice and Bob must do the work themselves. In one move, either of them picks their own
number and flips a single bit of it (a 0 becomes a 1, or a 1 becomes a 0). They want to reach
a OR b == c using as few moves in total as possible.
Given a, b and c, find the minimum number of bit flips needed.
You will be asked this for several independent triples (a, b, c); answer each one separately.
Input
The first line contains a single integer q (1 ≤ q ≤ 10^5), the number of triples.
Each of the next q lines contains three integers a, b, c (0 ≤ a, b, c < 2^60),
describing one independent wish.
Output
For each triple, print one line with a single integer: the minimum number of bit flips (across a
and b combined) needed so that a OR b equals c exactly.
Notes
Look at each bit position on its own:
- If a bit of
cis1, the same bit ofaorb(or both) must already be1, or exactly one of them must be flipped to1. - If a bit of
cis0, that bit must be0in bothaandb, so every1among that bit ofaandbmust be flipped.
Since the 60 bit positions never interact with each other, the total answer is the sum of the per-bit costs.