#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long piso(const long long &a, const long long &b) {
  if (a % b == 0) return (a / b) - 1;
  return a / b;
}
int main() {
  long long n, m, p1, p2;
  scanf("%I64d %I64d", &n, &m);
  long long g = gcd(n, m);
  n /= g;
  m /= g;
  int q, s1, s2;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %I64d %d %I64d", &s1, &p1, &s2, &p2);
    if (s1 == 1)
      p1 = piso(p1, n);
    else
      p1 = piso(p1, m);
    if (s2 == 1)
      p2 = piso(p2, n);
    else
      p2 = piso(p2, m);
    if (p1 == p2) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
