#include <vector>
#include <cassert>
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = s.length();
assert(n > 2);
assert(s[0] == 'y' && s[1] == '=');
int ptr = 2;
int M = 0, neg = 0;
if (s[ptr] == 'x') {
M = 1;
} else {
if (s[ptr] == '+') ptr += 1;
if (s[ptr] == '-') neg = 1, ptr += 1;
while (ptr < n && s[ptr] != 'x') {
assert('0' <= s[ptr] && s[ptr] <= '9');
M = M * 10 + s[ptr] - '0';
ptr += 1;
}
if (neg) M *= -1;
}
assert(s[ptr] == 'x');
ptr += 1;
int C = 0; neg = 0;
if (ptr < n && s[ptr] == '+') ptr += 1;
if (ptr < n && s[ptr] == '-') neg = 1, ptr += 1;
while (ptr < n) {
assert('0' <= s[ptr] && s[ptr] <= '9');
C = C * 10 + s[ptr] - '0';
ptr += 1;
}
if (neg) C *= -1;
int q;
cin >> q;
while (q--) {
long long x, y;
cin >> x >> y;
cout << (y == x * M + C ? "YES" : "NO") << '\n';
}
return 0;
}