/* * * * * * * * * * * * * *
# *
# @Author AYUSH AGRAWAL *
# *
# * * * * * * * * * * * * */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define M(x) (x%MOD + MOD)%MOD
#define _pb push_back
#define _mp make_pair
#define ff first
#define ss second
#define s(x) scanf("%lld",&x)
ll mul(ll x,ll y)
{ ll ans=1;
while(y>0)
{ if(y&1)
ans=(ans*x)%MOD;
y/=2;
x=(x*x)%MOD;
}
return ans;
};
/******************************************************************************************************/
struct qry
{
ll code;
ll eat;
ll in;
bool ans;
qry()
{
ans = false;
}
};
struct slot
{
ll code;
ll eat;
};
bool comp1(struct slot lhs, struct slot rhs)
{
return (double)lhs.eat/lhs.code>=(double)rhs.eat/rhs.code;
}
bool comp2(struct qry lhs, struct qry rhs)
{
return lhs.eat<rhs.eat;
}
bool comp3(struct qry lhs, struct qry rhs)
{
return lhs.in<rhs.in;
}
int main()
{
ll t,g=1;
s(t);
while(t--)
{
ll d,s,i,cc=0,ee=0;
s(d); s(s);
struct slot st[s];
for(i=0;i<s;i++)
s(st[i].code), s(st[i].eat), cc+=st[i].code;
sort(st,st+s,comp1);
struct qry qq[d];
for(i=0;i<d;i++)
{
s(qq[i].code);
s(qq[i].eat);
qq[i].in = i;
}
sort(qq,qq+d,comp2);
ll qin = 0,diff;
double frac,max_code;
for(i=0;i<s;i++)
{
frac = (double)st[i].code/st[i].eat;
while(qin<d && qq[qin].eat<=ee+st[i].eat)
{
diff = qq[qin].eat-ee;
max_code = (double)cc - (double)frac*diff;
if((double)qq[qin].code<=(double)max_code)
qq[qin].ans = true;
++qin;
}
cc-=st[i].code;
ee+=st[i].eat;
}
sort(qq,qq+d,comp3);
string fin;
for(i=0;i<d;i++)
if(qq[i].ans)
fin+='Y';
else
fin+='N';
cout<<"Case #"<<g<<": "<<fin<<"\n";
++g;
}
return 0;
}
CgovKiAqICogKiAqICogKiAqICogKiAqICogKiAqIAkJCiMgICAgICAgICAgICAgICAgICAgICAgICAgICo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