#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
std::mt19937 mt(time(0));
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  int q;
  cin >> n >> m >> q;
  long long g = gcd(n, m);
  for (int i = 0; i < int(q); ++i) {
    long long sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    sy = (sy - 1) / ((sx == 1 ? n : m) / g);
    ey = (ey - 1) / ((ex == 1 ? n : m) / g);
    if (sy == ey)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
