#include<stdio.h>
#define MaxSize 1900
void clear(int* A) {
    int i;
    for (i = 0; i < MaxSize; i++)A[i] = 0;
}
void recover(int* A) {
    int i;
    for (i = 0; i < MaxSize; i++)
        if (A[i] >= 100)A[i] = 100;
        else A[i] = 0;
}
int main() {
    int i, j, k, m, n;
    scanf("%d", &m);
    for (k = 0; k < m; k++) {
        scanf("%d", &n);
        int A[MaxSize], B[MaxSize], C[MaxSize], D[MaxSize];
        clear(A);
        clear(B);
        clear(C);
        clear(D);
        for (i = 0; i < n; i++) {
            scanf("%d", &A[i]);
            C[A[i]] = 100;
        }
        for (i = 0; i < n; i++) {
            scanf("%d", &B[i]);
            D[B[i]] = 100;
        }
        for (i = 0; i < MaxSize; i++) {
            int tag = 0;
            if (D[i] == 100) {
                printf("%d={", i);
                for (j = 0; j < MaxSize; j++) {
                    if (B[j] == i) {
                        C[A[j]]++;
                    }
                }
                for (j = 0; j < MaxSize; j++) {
                    if (C[j] != 0)
                        if (tag++ == 0)printf("%d=%d", j, C[j] - 100);
                        else printf(",%d=%d", j, C[j] - 100);
                }
                printf("}\n");
                recover(C);
            }
        }
    }
    return 0;

}