#include <bits/stdc++.h>
using namespace std;
long long hcf(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a > b)
    return hcf(a % b, b);
  else if (a < b)
    return hcf(b % a, a);
  else
    return a;
}
int main() {
  long long n, m;
  cin >> n >> m;
  int q;
  cin >> q;
  long long f = hcf(n, m);
  long long f1 = n / f;
  long long f2 = m / f;
  while (q--) {
    int s1, s2;
    long long e1, e2;
    cin >> s1 >> e1 >> s2 >> e2;
    if (s1 == s2) {
      if (s1 == 1) {
        if ((e1 - 1) / f1 == (e2 - 1) / f1)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
      } else {
        if ((e1 - 1) / f2 == (e2 - 1) / f2)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
      }
    } else {
      if (s1 == 1) {
        if ((e1 - 1) / f1 == (e2 - 1) / f2)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
      } else {
        if ((e1 - 1) / f2 == (e2 - 1) / f1)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
      }
    }
  }
  return 0;
}
