#include<bits/stdc++.h>
using namespace std;
int main()
{
string s; cin>>s;
int n = s.size();
int m=0,c=0,indx=2,digit;
bool minus_m = false,minus_c=false;
if(s[2]=='-') {minus_m=true; indx++;}
int i=0;
while(s[indx]!='x')
{
digit = s[indx]-'0';
m *=10;
m += digit;
++indx;
}
++indx;
if(minus_m) m*= (-1);
if(indx<n && s[indx]=='-') minus_c=true;
++indx;
while(indx<n)
{
digit = s[indx]-'0';
c *= 10;
c += digit;
++indx;
}
if(minus_c) c *= (-1);
int x,y;
int q; cin>>q; while(q--)
{
cin>>x>>y;
if(y==(m*x)+c) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}