#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

void cerr_bits(ll nyan){
    for(int i=31;i>=0;i--){
        if(nyan & (1 << i)) cout << 1;
        else cout << 0;
    }
    cout << endl;
}

int main(){
    int S;
    cin >> S;
    cin >> hex;
    cout << hex;

    for(int t_case=0;t_case<S;t_case++){
        vector<ll> nyan(8);
        for(int i=0;i<8;i++){
            cin >> nyan[i];
        }
        ll checksum;
        cin >> checksum;

        ll key = 0;

        for(int i=0;i<32;i++){
            ll sum = 0;
            for(int j=0;j<8;j++){
                sum += nyan[j] ^ key;
            }
            if((sum & (1ll << i)) != (checksum & (1ll << i))){
                key = key | (1ll << i);
            }
        }

        cout << key << endl;
    }
    return 0;
}