#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <bitset>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll f(string s) {
	ll res = 0, t = 1;

	for(int i = s.size()-1; i >= 0; i--) {
		if('0' <= s[i] && s[i] <= '9') {
			res += (s[i] - '0') * t;
		} else {
			res += (10 + (s[i] - 'a')) * t;
		}
		t *= 16;
	}
	return res;
}

int main() {
	int n;
	cin >> n;

	rep(q, n) {
		vector<string> v(9);
		vector<ll> t(9);
		rep(i, 9) {
			cin >> v[i];
			t[i] = f(v[i]);
		}

		ll ans = 0;

		vector< vector<int> > bit(9, vector<int>(32));
		rep(i, 9) {
			rep(j, 32) {
				if(t[i] & (1LL << j)) {
					bit[i][j] = 1;
				}
			}
		}

		ans = 0;
		ll sum = 0;
		rep(i, 32) {
			ll d = 0;
			rep(j, 8) {
				d += bit[j][i];
			}
			bitset<32> ss(sum);

			if( ((((sum >> i) & 1) + d) & 1) == bit[8][i]) {
				sum += (d << i);
			} else {
				d = 0;
				rep(j, 8) {
					d += bit[j][i] ^ 1;
				}
				sum += (d << i);
				ans += (1LL << i);
			}
		}

		cout << hex << ans << endl;
	}

	return 0;
}