problems / 259

Alice and Bob's Bit Disagreement

easy bit-manipulation 1000 ms · 256 MB

Alice and Bob's Bit Disagreement

Alice and Bob have invented a quick game for rainy afternoons. In each round, both of them secretly write down a 64-bit unsigned integer and then reveal it. They line the two numbers up in binary, each padded with leading zeros to exactly 64 digits, and compare them digit by digit. Every position where one of them wrote a 0 and the other wrote a 1 is a disagreement, and the round's score is the number of disagreements.

For example, Alice writes 5 (binary ...0101) and Bob writes 3 (binary ...0011). They disagree in the two lowest positions and agree everywhere else, so the score is 2.

Given the numbers from all q rounds, print the score of each round.

Input

The first line contains an integer q (1 ≤ q ≤ 10^5), the number of rounds.

Each of the next q lines contains two integers a and b (0 ≤ a, b ≤ 2^64 − 1 = 18446744073709551615), the numbers written by Alice and Bob in that round.

Output

Print q lines. The i-th line must contain a single integer: the number of bit positions where the two numbers of the i-th round differ.

Notes

In the first example, 5 and 3 differ in two positions; 0 and 0 agree everywhere; 12 (1100) and 10 (1010) differ in the two middle positions; and 7 and 8 (0111 against 1000) differ in all four lowest positions.

In the second example, the numbers are at the top of the allowed range. 18446744073709551615 is 2^64 − 1, all 64 bits set, so against 0 every position is a disagreement. 9223372036854775808 is 2^63, only the highest bit set. These values do not fit in a signed 64-bit integer: read them into an unsigned 64-bit type (unsigned long long in C and C++, uint64 in Go).

Example 1

Input

4
5 3
0 0
12 10
7 8

Output

2
0
2
4

Example 2

Input

4
18446744073709551615 0
9223372036854775808 0
18446744073709551615 9223372036854775808
4294967296 4294967295

Output

64
1
63
33

Hints · reveal one at a time if you're stuck

Hint 1

Is there a bitwise operation that produces a 1 exactly in the positions where two numbers differ?

Hint 2

XOR does exactly that, so what remains is counting the 1 bits of one number, known as the Hamming weight. Make sure every bit of all 64 is counted, and that your integer type is unsigned 64-bit.

report an issue Prefer your own editor? sooks prep 259 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.