#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

struct Info{
	int ans[32],kuriagari[32],current_digit;
};

int input[8][32],check_sum[32],ANS[32];

void toBit(char ch,int table[32],int start){

	switch(ch){
	case '0':
		table[start] = 0,table[start+1] = 0,table[start+2] = 0,table[start+3] = 0;
		break;
	case '1':
		table[start] = 0,table[start+1] = 0,table[start+2] = 0,table[start+3] = 1;
		break;
	case '2':
		table[start] = 0,table[start+1] = 0,table[start+2] = 1,table[start+3] = 0;
		break;
	case '3':
		table[start] = 0,table[start+1] = 0,table[start+2] = 1,table[start+3] = 1;
		break;
	case '4':
		table[start] = 0,table[start+1] = 1,table[start+2] = 0,table[start+3] = 0;
		break;
	case '5':
		table[start] = 0,table[start+1] = 1,table[start+2] = 0,table[start+3] = 1;
		break;
	case '6':
		table[start] = 0,table[start+1] = 1,table[start+2] = 1,table[start+3] = 0;
		break;
	case '7':
		table[start] = 0,table[start+1] = 1,table[start+2] = 1,table[start+3] = 1;
		break;
	case '8':
		table[start] = 1,table[start+1] = 0,table[start+2] = 0,table[start+3] = 0;
		break;
	case '9':
		table[start] = 1,table[start+1] = 0,table[start+2] = 0,table[start+3] = 1;
		break;
	case 'a':
		table[start] = 1,table[start+1] = 0,table[start+2] = 1,table[start+3] = 0;
		break;
	case 'b':
		table[start] = 1,table[start+1] = 0,table[start+2] = 1,table[start+3] = 1;
		break;
	case 'c':
		table[start] = 1,table[start+1] = 1,table[start+2] = 0,table[start+3] = 0;
		break;
	case 'd':
		table[start] = 1,table[start+1] = 1,table[start+2] = 0,table[start+3] = 1;
		break;
	case 'e':
		table[start] = 1,table[start+1] = 1,table[start+2] = 1,table[start+3] = 0;
		break;
	case 'f':
		table[start] = 1,table[start+1] = 1,table[start+2] = 1,table[start+3] = 1;
		break;
	}
}

char toNum(int table[32],int digit){
	int start = 32 - 4*digit;
	int number = 8*table[start] + 4*table[start+1] + 2*table[start+2] + table[start+3];

	if(number <= 9)return '0' + number;
	else{
		switch(number){
		case 10:return 'a';
		case 11:return 'b';
		case 12:return 'c';
		case 13:return 'd';
		case 14:return 'e';
		case 15:return 'f';
		}
	}

	return 'z';	//must not reach here
}


void func(){
	int length,start;
	char buf[10];

	for(int i = 0; i < 8; i++){
		for(int k = 0; k < 32; k++)input[i][k] = 0;
		check_sum[i] = 0;
	}

	for(int i = 0; i < 8; i++){
		scanf("%s",buf);
		for(length = 0; buf[length] != '\0';length++);

		start = 32-4*length;

		for(int k = 1; k <= length; k++){
			toBit(buf[k-1],input[i],start+4*(k-1));
		}
	}

	scanf("%s",buf);
	for(length = 0; buf[length] != '\0';length++);

	start = 32-4*length;

	for(int k = 1; k <= length; k++){
		toBit(buf[k-1],check_sum,start+4*(k-1));
	}

	Info first;
	for(int i = 0; i < 32; i++){
		first.ans[i] = -1;
		first.kuriagari[i] = 0;
	}
	first.current_digit = 32;

	queue<Info> Q;
	Q.push(first);

	int calc_0,calc_1;

	while(!Q.empty()){

		if(Q.front().current_digit == 0){
			for(int i = 0; i < 32; i++){
				ANS[i] = Q.front().ans[i];
			}
			break;
		}

		calc_0 = 0;
		for(int i = 0; i < 8; i++){
			if(input[i][Q.front().current_digit-1] == 1)calc_0++;
		}

		calc_0 += Q.front().kuriagari[Q.front().current_digit-1];

		calc_1 = 0;
		for(int i = 0; i < 8; i++){
			if(input[i][Q.front().current_digit-1] == 0)calc_1++;
		}
		calc_1 += Q.front().kuriagari[Q.front().current_digit-1];

		if(calc_0%2 == check_sum[Q.front().current_digit-1]){

			Info new_info;
			for(int k = 0; k < 32; k++){
				new_info.ans[k] = Q.front().ans[k];
				new_info.kuriagari[k] = Q.front().kuriagari[k];
			}
			new_info.current_digit = Q.front().current_digit-1;
			new_info.ans[Q.front().current_digit-1] = 0;

			switch(calc_0){
			case 11:
			case 10:
				if(Q.front().current_digit >= 4){
					new_info.kuriagari[Q.front().current_digit-4] += 1;
				}
				if(Q.front().current_digit >= 2){
					new_info.kuriagari[Q.front().current_digit-2] += 1;
				}
				break;
			case 9:
			case 8:
				if(Q.front().current_digit >= 4){
					new_info.kuriagari[Q.front().current_digit-4] += 1;
				}
				break;
			case 7:
			case 6:
				if(Q.front().current_digit >= 3){
					new_info.kuriagari[Q.front().current_digit-3] += 1;
					new_info.kuriagari[Q.front().current_digit-2] += 1;
				}else{
					if(Q.front().current_digit == 2){
					new_info.kuriagari[Q.front().current_digit-2] += 1;
					}
				}
				break;
			case 5:
			case 4:
				if(Q.front().current_digit >= 3){
					new_info.kuriagari[Q.front().current_digit-3] += 1;
				}
				break;
			case 3:
			case 2:
				if(Q.front().current_digit >= 2){
					new_info.kuriagari[Q.front().current_digit-2] += 1;
				}
				break;
			case 1:
			case 0:
				break;
			}

			Q.push(new_info);
		}

		if(calc_1%2 != check_sum[Q.front().current_digit-1]){

			Info new_info;
			for(int k = 0; k < 32; k++){
				new_info.ans[k] = Q.front().ans[k];
				new_info.kuriagari[k] = Q.front().kuriagari[k];
			}
			new_info.current_digit = Q.front().current_digit-1;
			new_info.ans[Q.front().current_digit-1] = 1;

			switch(calc_1){
			case 11:
			case 10:
				if(Q.front().current_digit >= 4){
					new_info.kuriagari[Q.front().current_digit-4] += 1;
				}
				if(Q.front().current_digit >= 2){
					new_info.kuriagari[Q.front().current_digit-2] += 1;
				}
				break;
			case 9:
			case 8:
				if(Q.front().current_digit >= 4){
					new_info.kuriagari[Q.front().current_digit-4] += 1;
				}
				break;
			case 7:
			case 6:
				if(Q.front().current_digit >= 3){
					new_info.kuriagari[Q.front().current_digit-3] += 1;
					new_info.kuriagari[Q.front().current_digit-2] += 1;
				}else{
					if(Q.front().current_digit == 2){
					new_info.kuriagari[Q.front().current_digit-2] += 1;
					}
				}
				break;
			case 5:
			case 4:
				if(Q.front().current_digit >= 3){
					new_info.kuriagari[Q.front().current_digit-3] += 1;
				}
				break;
			case 3:
			case 2:
				if(Q.front().current_digit >= 2){
					new_info.kuriagari[Q.front().current_digit-2] += 1;
				}
				break;
			case 1:
			case 0:
				break;
			}
			Q.push(new_info);
		}

		Q.pop();
	}

	char output[8];

	for(int digit = 8; digit >= 1; digit--){
		output[8-digit] = toNum(ANS,digit);
	}

	bool First = true;

	for(int i = 0; i < 8; i++){
		if(output[i] != '0'){
			First = false;
			printf("%c",output[i]);
		}else{
			if(!First){
				printf("%c",output[i]);
			}else{
				if(i == 7)printf("0");
			}
		}
	}
	printf("\n");

}

int main(){

	int N;
	scanf("%d",&N);
	for(int loop = 0; loop < N; loop++){
		func();
	}

    return 0;
}

Measured memory_bytes: 3168