#include <bits/stdc++.h>
using namespace std;
long long find(long long a, long long b) {
  while (1) {
    if (a > b)
      a = a % b;
    else
      b = b % a;
    if (a == 0 || b == 0) return a + b;
  }
}
int main() {
  long long n, m;
  int q;
  scanf("%lld%lld%d", &n, &m, &q);
  long long x = find(n, m);
  long long dis[5];
  dis[1] = n / x;
  dis[2] = m / x;
  for (int as = 0; as < q; as++) {
    long long sx, sy, ex, ey;
    scanf("%lld%lld%lld%lld", &sx, &sy, &ex, &ey);
    if ((sy - 1) / dis[sx] == (ey - 1) / dis[ex])
      printf("YES\n");
    else
      printf("NO\n");
  }
}
