#include <bits/stdc++.h>
using namespace std;
long long int a, b;
long long int gcd(long long int n, long long int m) {
  if (m == 0) return n;
  n %= m;
  return gcd(m, n);
}
long long int block(long long int x, long long int y) {
  if (x == 1) {
    return ceil((y - a) / (a * 1.0)) + 1;
  } else {
    return ceil((y - b) / (b * 1.0)) + 1;
  }
}
int main() {
  long long int iner, out, n, m, q, gc, x, y, s, t;
  cin >> n >> m >> q;
  gc = gcd(n, m);
  a = n / gc;
  b = m / gc;
  while (q--) {
    cin >> x >> y >> s >> t;
    iner = block(x, y);
    out = block(s, t);
    if (iner == out) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
}
