#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ll long long int
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mx_ele(v) *max_element(v.begin(),v.end())
#define mnm_ele(v) *min_element(v.begin(),v.end())
#define endl "\n"
using namespace std;
void smile()
{
string eqn;
cin >> eqn;
int slope = 0, c = 0;
if (eqn.size() == 6)
{
eqn[2] = eqn[2] - '0';
eqn[5] = eqn[5] - '0';
slope = eqn[2];
c = eqn[5];
if (eqn[4] == '-')
c = (-1) * c;
}
else if (eqn.size() == 7)
{
eqn[3] = eqn[3] - '0';
eqn[6] = eqn[6] - '0';
slope = (-1) * eqn[3];
c = eqn[6];
if(eqn[5]=='-')
c=(-1)*c;
}
else if (eqn.size() == 5 and eqn[2]=='-')
{
eqn[3] = eqn[3] - '0';
slope = eqn[3];
if (eqn[2] == '-')
slope = (-1) * slope;
c = 0;
}
else if(eqn.size()==5 and eqn[2]=='x')
{
slope=1;
eqn[4]=eqn[4]-'0';
c=eqn[4];
if(eqn[3]=='-')
c=(-1)*c;
}
else if (eqn.size() == 4 and eqn[3] == 'x')
{
eqn[2] = eqn[2] - '0';
slope = eqn[2];
c = 0;
}
else if (eqn.size() == 3)
{
eqn[2] = eqn[2] - '0';
slope = 0;
c = eqn[2];
}
else if (eqn.size() == 4)
{
slope = 0;
eqn[3] = eqn[3] - '0';
c = (-1) * eqn[3];
}
int t;
cin>>t;
while(t--)
{
int x,y;
cin>>x>>y;
int first=slope*x;
int fina=first+c;
if(fina==y)
yes;
else no;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
{
smile();
}
return 0;
}