#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 1e5 + 3;
void mf() { freopen("input.in", "r", stdin); }
long long n, m, q, msec, nsec;
long long ff(long long type, long long x) {
  long long sec = type == 1 ? nsec : msec;
  return floor((x - 1) / sec);
}
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
  cin >> n >> m >> q;
  long long xx = gcd(n, m);
  nsec = n / xx;
  msec = m / xx;
  for (int i = 1; i <= q; i++) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long secA = ff(a, b);
    long long secC = ff(c, d);
    if (secA == secC) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
