ll@n,@q,a[2n]{},b[]{};string@s;rep(i,2n-1)@[a,b][i+1]=@[a,b][i]+(s[i%n]@[=,!]='D');rep(q){ll@h--,@w--,@p,x=ll_inf,y=x,d;if(d=a[n])x=h/d*n+bsearch_min[ll,j,p,p+n](a[j]-a[p]>h%d);if(d=b[n])y=w/d*n+bsearch_min[ll,j,p,p+n](b[j]-b[p]>w%d);wt(min(x,y)%n);}