#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
long long n, m, q, a, b, c, d, temp;
int main() {
  scanf("%lld%lld%lld", &n, &m, &q);
  temp = gcd(n, m);
  n = n / temp;
  m = m / temp;
  while (q--) {
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    b--;
    d--;
    if (a == 1)
      b /= n;
    else
      b /= m;
    if (c == 1)
      d /= n;
    else
      d /= m;
    if (b == d)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
