#include <bits/stdc++.h>
int n = 0, m = 0;
long long d = 0, lcm = 0;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void exgcd(int a, int b, long long &x, long long &y) {
  if (b) {
    exgcd(b, a % b, y, x);
    y -= x * (a / b);
  } else {
    x = 1;
    y = 0;
  }
}
long long calc(int x, int y) {
  if ((y - x) % d) {
    return -1;
  } else {
    long long s = 0, t = 0;
    exgcd(n, m, s, t);
    s *= (y - x) / d;
    s = (n * s + x) % lcm;
    return (s + lcm) % lcm;
  }
}
long long solve(int x, int y) {
  long long ans = lcm;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      long long t = calc(i ? n - x : x, j ? m - y : y);
      if (t != -1) {
        if (((t / n) & 1) == i && ((t / m) & 1) == j) {
          ans = std::min(ans, t);
        }
      }
    }
  }
  return ans == lcm ? -1 : ans;
}
int main() {
  int k = 0;
  scanf("%d%d%d", &n, &m, &k);
  d = gcd(n, m);
  lcm = (long long)n * (long long)m / d;
  for (int i = 0; i < k; i++) {
    int x = 0, y = 0;
    scanf("%d%d", &x, &y);
    printf("%I64d\n", solve(x, y));
  }
  return 0;
}
