#include <bits/stdc++.h>
using namespace std;
long long n, m, q;
long long sx, sy, ex, ey;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
signed main() {
  cin >> n >> m >> q;
  for (long long i = 0; i < q; i++) {
    cin >> sx >> sy >> ex >> ey;
    sy--;
    ey--;
    if (gcd(n, m) == 1)
      puts("YES");
    else {
      long long memo = gcd(n, m), s, e;
      if (sx == 1)
        s = sy / (n / gcd(n, m));
      else
        s = sy / (m / gcd(n, m));
      if (ex == 1)
        e = ey / (n / gcd(n, m));
      else
        e = ey / (m / gcd(n, m));
      if (s != e)
        puts("NO");
      else
        puts("YES");
    }
  }
  return 0;
}
