import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

uint N[9];
void input() {
    foreach (i; 0 .. 9) {
        scanf("%0x", &N[i]);
    }
}

bool biteq(uint x, uint a, uint b) {
    return ((a & (1 << x)) == (b & (1 << x)));
}

void solve() {
    uint x = 0;
    for (uint i = 0; i < 32; i++) {
        uint y = x;
        //writefln("%d: %0x", i, y);
        uint s = 0;
        foreach (j; 0 .. 8) {
            s += (N[j] ^ y);
        }
        if (s == (N[8] ^ y)) {
            writefln("%0x", y);
            return;
        }
        if (biteq(i, s, N[8] ^ y)) {
            x = y;
            continue;
        }
        s = 0;
        y = x | (1 << i);
        foreach (j; 0 .. 8) {
            s += (N[j] ^ y);
        }
        if (s == (N[8] ^ y)) {
            writefln("%0x", y);
            return;
        }
        if (biteq(i, s, N[8] ^ y)) {
            x = y;
            continue;
        }
        writefln("%0x", x);
    }
}
 
void main() {
    int T; scanf("%d\n", &T);
    foreach (t; 1 .. T + 1) {
        input;
        solve;
    }
}