#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int main() {
  ll n, m, q;
  cin >> n >> m >> q;
  ll g = gcd(n, m);
  while (q--) {
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    --sy;
    --ty;
    if (sx == 1)
      sy /= (n / g);
    else
      sy /= (m / g);
    if (tx == 1)
      ty /= (n / g);
    else
      ty /= (m / g);
    cout << (sy == ty ? "YES" : "NO") << endl;
  }
  return 0;
}
