#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long int n, m, q, g;
  cin >> n >> m >> q;
  g = gcd(n, m);
  long long int s[3];
  s[1] = n / g;
  s[2] = m / g;
  while (q--) {
    long long int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    if ((sy - 1) / s[sx] == (ey - 1) / s[ex])
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
