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