#include <bits/stdc++.h>
using namespace std;
long long n, b, k, m, q, a;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long get_sector(pair<long long, long long> x) {
  x.second--;
  if (x.first == 1) {
    return x.second / a;
  }
  return x.second / b;
}
int main() {
  cin >> n >> m >> q;
  long long g = gcd(n, m);
  a = n / g;
  b = m / g;
  while (q--) {
    pair<long long, long long> x, y;
    cin >> x.first >> x.second >> y.first >> y.second;
    long long f = get_sector(x);
    long long s = get_sector(y);
    if (f == s)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
