// #include <iostream>
// #include <string>
// #include <vector>
// #include <set>
// #include <unordered_set>
// #include <map>
// #include <list>
// #include <algorithm>
// #include <numeric>
// #include <cmath>
#include <bits/stdc++.h>
#define ll long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v) reverse(v.begin(), v.end())
#define REV_SORT(v) sort((v).begin(), (v).end(), greater<>())
#define vint vector<int>
#define vll vector<ll>
#define vch vector<char>
#define vstr vector<string>
#define u_set unordered_set
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define fast \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
void debug()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve();
int32_t main()
{
fast;
// debug();
int TestCase = 1;
// cin >> TestCase;
while (TestCase--)
solve();
return 0;
}
void solve()
{
string eqn;
cin >> eqn;
string mm;
int i = 2;
while (eqn[i] != 'x')
{
mm += eqn[i];
i++;
}
string cc;
if (i + 1 == eqn.size())
{
cc = '0';
}
else
{
i++;
while (i != eqn.size())
{
cc += eqn[i];
i++;
}
}
int m = stoi(mm);
int c = stoi(cc);
int q;
cin >> q;
while (q--)
{
int x, y;
cin >> x >> y;
if (y == (m * x) + c)
{
yes;
}
else
{
no;
}
}
}