#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

LL htoi(string &s){
  LL ans=0;
  rep(i,s.length()){
    ans*=16;
    if('0'<=s[i]&&s[i]<='9') ans+=s[i]-'0';
    else ans+=s[i]-'a'+10;
  }
  return ans;
}

string itoh(LL x){
  string ans="";
  while(x){
    if(x%16<=9) ans.push_back('0'+x%16);
    else ans.push_back('a'+x%16-10);
    x/=16;
  }
  if(ans.size()==0) ans="0";
  reverse(all(ans));
  return ans;
}

int main(){
  int q;
  cin >> q;
  rep(t,q){
    string s;
    vector<LL> p(9),q(9);
    rep(i,9){
      cin >> s;
      p[i]=htoi(s);
      q[i]=p[i]%65536;
      p[i]/=65536;
    }
    map<LL,vector<LL>> mp;
    rep(i,65536){
      LL sum=0;
      rep(j,8) sum+=(p[j]^i);
      sum%=65536;
      mp[(p[8]^i)-sum].push_back(i);
    }
    rep(i,65536){
      LL sum=0;
      rep(j,8) sum+=(q[j]^i);
      if(sum%65536==(q[8]^i)){
        auto itr=mp.find(sum/65536);
        if(itr!=mp.end()){
          vector<LL> &v = itr->second;
          for(LL x:v){
            sum=0;
            rep(j,8) sum+=((p[j]*65536+q[j])^(x*65536+i));
            sum%=65536LL*65536;
            if(sum==(p[8]*65536+q[8])^(x*65536+i)){
              cout << itoh(x*65536+i) << endl;
              goto next;
            }
          }
        }
      }
    }
    next:;
  }
  return 0;
}

