#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
string s;
cin>>ws;
cin>>s;
int r,l,u,d;
r=l=u=d=0;
for(char c:s){
if(c=='R')r++;
else if(c=='L')l++;
else if(c=='U')u++;
else d++;
}
int a,b,q;
cin>>a>>b;
cin>>q;
while(q--){
int x,y;
cin>>x>>y;
int ii=x-a,jj=y-b;
int ansi,ansj;
int flag=1;
if(ii>0){
if(r<ii)flag=0;
else ansi=ii;
}
else{
ii*=-1;
if(l<ii)flag=0;
else ansi=ii;
}
if(jj>0){
if(u<jj)flag=0;
else ansj=jj;
}
else{
jj*=-1;
if(d<jj)flag=0;
else ansj=jj;
}
if(flag){
cout<<"YES"<<' '<<ansi+ansj;
}
else cout<<"NO";
if(q)cout<<'\n';
}
if(t)cout<<'\n';
}
return 0;
}
Comments
Post a Comment