#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; int c1[150], c2[150], c3[150]; bool check(int a, int b) { for(int i = 65; i <= 90; ++i) if(a * c1[i] + b * c2[i] != c3[i]) return false; return true; } int main() { int _; cin >> _; while(_ --) { int A, B, C; cin >> A >> B >> C; memset(c1, 0, sizeof c1); memset(c2, 0, sizeof c2); memset(c3, 0, sizeof c3); char x; int c; int tot = A; while(tot --) { cin >> x >> c; c1[x] += c; } tot = B; while(tot --) { cin >> x >> c; c2[x] += c; } tot = C; while(tot --) { cin >> x >> c; c3[x] += c; } int flag = 0; for(int a = 1; a <= 100; ++a) { for(int b = 1; b <= 100; ++b) { if(check(a, b)) { cout << a << ' ' << b << endl; flag = 1; break;} } if(flag) break; } if(!flag) puts("NO"); } return 0; }