#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

int compare(const void* a, const void* b)
{
	const int* x = (int*) a;
	const int* y = (int*) b;

	if (*x > *y)
		return 1;
	else if (*x < *y)
		return -1;

	return 0;
}

int main() {
    
    int N,M,T,i,j,br,x,k,o;
    int A[N];
    int B[M];
    int C[N+M];
    int R[T];
    
    cin >> T;
    for (br = 1; br <= T; br++) {
        cin >> N;
        cin >> M;
        for (i = 1; i <= N; i++) {
            cin >> A[i];
            C[i] = A[i];
        }
        for (j = 1; j <= M; j++) {
            cin >> B[j];
            C[N + j] = B[j];
        }
        qsort(C,N+M,sizeof(int),compare);
        R[i] = 1;
        x = C[2] - C[1];
        for (k = 1; k <= N + M; k++) {
        if (C[k + 1] - C[k] == x) {}
        else {
            R[br] = 0;
        }
    }
    for (o = 1; o <= T; o++) {
        cout << C[o] << endl;
    }
    return 0;
    }
}