#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);
}
int main() {
  long long n, m;
  int k;
  cin >> n >> m;
  cin >> k;
  long long a, b, c, d;
  long long g[3];
  long long x = gcd(n, m);
  g[1] = (n / x);
  g[2] = (m / x);
  while (k--) {
    cin >> a >> b >> c >> d;
    long long s1 = (b - 1) / g[a];
    long long s2 = (d - 1) / g[c];
    if (s1 == s2 || x == 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
