#include <bits/stdc++.h>
using namespace std;
long long n, m, q;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  cin >> n >> m >> q;
  long long v = gcd(n, m);
  long long innersize = n / v;
  long long outersize = m / v;
  for (int i = 0; i < q; i++) {
    long long s1, x1, s2, x2;
    cin >> s1 >> x1 >> s2 >> x2;
    x1--;
    x2--;
    if (s1 == 1) {
      x1 /= innersize;
    } else {
      x1 /= outersize;
    }
    if (s2 == 1) {
      x2 /= innersize;
    } else {
      x2 /= outersize;
    }
    if (x1 == x2) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
}
