Under construction

Still being built. Things may change

Finding the Weakness in the Encryption

Time limit1sMemory limit128 MB

Summary
Given nine XOR-encrypted 32-bit values where the last is a checksum of the others, recover the XOR key bit by bit using carry propagation.
Level

Medium6 of 10

Topics
Bit manipulation, Math, Simulation
Solved
No attempts yet

Problem

You want to encrypt and transmit some data given as eight 32-bit unsigned integers.

N1 N2 N3 … N8N_1\ N_2\ N_3\ \ldots\ N_8

First, to check that the data is correct, you compute a checksum and append it as a ninth value. (A checksum is a common way to verify data integrity.)

N9=(∑i=18Ni) mod 232N_9 = \left(\sum_{i=1}^{8} N_i\right) \bmod 2^{32}

Then you encrypt these nine numbers with a 32-bit key KK. Encryption is done with the XOR operation. (XOR is an operation frequently used to encrypt data.)

M1=N1⊕K,M2=N2⊕K,…,M9=N9⊕KM_1 = N_1 \oplus K,\quad M_2 = N_2 \oplus K,\quad \ldots,\quad M_9 = N_9 \oplus K

If you transmit the nine values M1M_1 through M9M_9, anyone who knows KK can recover the original data N1N_1 through N8N_8. And someone who does not know KK can recover N1N_1 through N8N_8 as well... surprisingly!

This scheme has a weakness. Exploit it: given the nine integers M1M_1 through M9M_9 in hexadecimal, write a program that finds the key KK.

Input

The first line contains the number of test cases TT. TT does not exceed 10001000.

Then, for each test case, nine integers M1M_1 through M9M_9 are given in hexadecimal. Each hexadecimal number uses only the digits 0–9 and the lowercase letters a–f, with no unnecessary leading zeros. The nine numbers of a test case are not necessarily all on one line.

Output

For each test case, print the key KK in lowercase hexadecimal on its own line, with no unnecessary leading zeros.

Hint

Spoiler warning. The key is the relation N9=(∑i=18Ni) mod 232N_9 = \left(\sum_{i=1}^{8} N_i\right) \bmod 2^{32}. When you add the eight values Ni=Mi⊕KN_i = M_i \oplus K, the parity of the bit sum at each position does not depend on that position's key bit kjk_j. So, starting from the least significant bit and tracking the addition carry, you can determine each bit of KK uniquely, one at a time.

Examples2

  1. Example 1

    Input
    8
    1 1 1 1 1 1 1 1 8
    3 2 3 2 3 2 3 2 6
    3 4 4 7 7 b a 2 2e
    e1 13 ce 28 ca 6 ab 46 a6d
    b08 49e2 6128 f27 8cf2 bc50 7380 7fe1 723b
    4eba eb4 a352 fd14 6ac1 eed1 dd06 bb83 392bc
    ef593c08 847e522f 74c02b9c 26f3a4e1 e2720a01 6fe66007
    7a4e96ad 6ee5cef6 3853cd88
    60202fb8 757d6d66 9c3a9525 fbcd7983 82b9571c ddc54bab 853e52da
    22047c88 e5524401
    
    Expected output
    0
    2
    6
    1c6
    4924afc7
    ffff95c5
    546991d
    901c4a16
    
  2. Example 2

    Input
    1
    1234abcc 1234abcf 1234abce 1234abc9 1234abc8 1234abcb 1234abca 1234abc5 1234abe9
    
    Expected output
    1234abcd