#include<iostream>
#include<cstdio>
using namespace std;
int t;
int main()
{
	cin>>t;
	while(t--)
	{
		unsigned int a[8],c,k=0,d=1,m=0;
		for(int i=0;i<8;i++)scanf("%x",&a[i]);
		scanf("%x",&c);
		for(int i=0;i<32;i++)
		{
			unsigned int now=0,sum=0;
			for(int j=0;j<8;j++)
			{
				now+=a[j]/d%2;
				sum+=(a[j]&m)^k;
			}
			now+=sum/d;
			k|=(c/d%2!=now%2)*d;
			d<<=1;
			m=d-1;
		}
		printf("%x\n",k);
	}
}

