#include #include #include #include #include #include #include #include #include #include #include #include #define mem(a)memset(a,0,sizeof(a)) #define rep(i,a,n) for(i=a;ia;i--) #define LL long long #define max(a,b)a>b?a:b #define min(a,b)a>T; while(T--){ cin>>A>>B>>C; mem(via); rep(i,0,A){ cin>>x>>c; via[x-'A']=c; }mem(vib); rep(i,0,B){ cin>>x>>c; vib[x-'A']=c; } mem(vic); rep(i,0,C){ cin>>x>>c; vic[x-'A']=c; }flag=0; rep(i,1,101){ rep(j,1,101){ rep(k,0,26){ if(i*via[w[k]-'A']+j*vib[w[k]-'A']!=vic[w[k]-'A']){ break; } } if(k==26)break; } if(k==26)break; } if(k==26)printf("%d %d\n",i,j); else puts("NO"); }return 0; }