#include #include #include using namespace std; typedef long long ll; int A[30],B[30],C[30]; int main() { int a,b,c; int t; cin >> t; while(t--) { cin >> a >> b >> c; char ch; int num; getchar(); memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); memset(C,0,sizeof(C)); for(int i = 0;i < a;i++) { scanf("%c %d",&ch,&num); getchar(); A[ch - 'A'] = num; } for(int i = 0;i < b;i++) { scanf("%c %d",&ch,&num); getchar(); B[ch - 'A'] = num; } for(int i = 0;i < c;i++) { scanf("%c %d",&ch,&num); getchar(); C[ch - 'A'] = num; } bool yes = 0; int m = 0,n = 0; for(int i = 1;i <= 100;i++) { for(int j = 1;j <= 100;j++) { bool ok = 1; for(int k = 0;k < 26;k++) { if(i*A[k]+j*B[k] != C[k]) { ok = 0; break; } } if(ok) { yes = 1; m = i; n = j; break; } } if(yes) break; } if(yes) printf("%d %d\n",m,n); else printf("NO\n"); } return 0; }