#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll num[9];

string out(ll n){
  string res,o="0123456789abcdef";
  if(n>=16) return out(n/16)+o[n%16];;
  return res+o[n%16];
}

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

ll ans;
bool saiki(ll a,ll b,int kai){
  if(kai==33)return true;
  ll sum0=0,sum1=0,c;
  for(int i=0;i<8;i++) {
    c=(num[i]>>kai)%2;
    sum0+=(c^0);
    sum1+=(c^1);
  }
  
  c=(num[8]>>kai)%2;
  
  ll na=a+(sum0<<kai);
  ll nb=b+((c^0)<<kai);
  if(na%(1LL<<kai)==nb%(1LL<<kai)&&saiki(na,nb,kai+1))return true;
  
  na=a+(sum1<<kai);
  nb=b+((c^1)<<kai);
  if(na%(1LL<<kai)==nb%(1LL<<kai) && saiki(na,nb,kai+1)) {
    ans|=(1LL<<kai);
    return true;
  }

  return false;
}

int main(){
  int q;
  cin >>q;
  while(q--){
    string str;
    for(int i=0;i<9;i++)cin>>str,num[i]=s2i(str);
    ans=0;
    saiki(0,0,0);
    cout<<out(ans)<<endl;
  }
  return 0;
}