#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long n, m, g, q, a1, a2, b1, b2, fz[3];
int main() {
  cin >> n >> m >> q;
  g = gcd(n, m);
  fz[1] = n / g;
  fz[2] = m / g;
  while (q--) {
    cin >> a1 >> a2 >> b1 >> b2;
    if ((a2 - 1) / fz[a1] == (b2 - 1) / fz[b1])
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
