#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * t;
}
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
long long h, w, k, m, a[200005];
long long q(int x, int y) {
  int z = (y - x + h * w * 100) % h;
  return a[z] * w + x;
}
long long f(int x, int y) {
  long long g =
      min(min(q(x, y), q(w - x, y)), min(q(x, h - y), q(w - x, h - y)));
  return g > m ? -1 : g;
}
int main() {
  w = read(), h = read(), k = read();
  m = h * w / gcd(h, w);
  h <<= 1, w <<= 1;
  for (int i = 0; i < h; i++) a[i] = 0x3f3f3f3f;
  for (int i = h; ~i; i--) a[w * i % h] = i;
  for (int i = 1; i <= k; i++) {
    int x = read(), y = read();
    printf("%lld\n", f(x, y));
  }
}
