#include int getint() { int r = 0; char c; for (c = getchar(); c < '0' || c > '9'; c = getchar()); for (; '0' <= c && c <= '9'; c = getchar()) r = r * 10 - '0' + c; return r; } char getele() { char c; for (c = getchar(); c < 'A' || c > 'Z'; c = getchar()); return c; } const int maxe = 30; const int maxc = 150; int T, A, B, C; int a[maxc], b[maxc], c[maxc]; bool check(int x, int y){ for (int i = 'A'; i <= 'Z'; ++i) { if (c[i] != a[i] * x + b[i] * y) return false; } return true; } int main() { T = getint(); char e; int t; while (T--) { for (int i = 0; i < maxc; ++i) a[i] = b[i] = c[i] = 0; A = getint(); B = getint(); C = getint(); for (int i = 0; i < A; ++i) { e = getele(); t = getint(); a[e] += t; } for (int i = 0; i < B; ++i) { e = getele(); t = getint(); b[e] += t; } for (int i = 0; i < C; ++i) { e = getele(); t = getint(); c[e] += t; } bool success = false; for (int x = 1; x <= 100; ++x) { for (int y = 1; y <= 100; ++y) { if (check(x, y)) { printf("%d %d\n", x, y); success = true; } if (success) break; } if (success) break; } if (!success) { printf("NO\n"); } } return 0; }