#include <bits/stdc++.h>
using namespace std;
long long n, m;
int q;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, x, y);
  long long t = x;
  x = y;
  y = t - a / b * y;
}
long long work(long long a, long long b, long long c, long long d) {
  if (a < c) swap(a, c), swap(b, d);
  long long G = gcd(a, c), k = d - b;
  if (k % G != 0) return 1ll << 50;
  a /= G, c /= G, k /= G;
  long long x, y;
  exgcd(a, c, x, y);
  x *= k;
  x = (x % c + c) % c;
  long long res = G * a * x + b;
  return res;
}
int main() {
  long long x, y, ans;
  scanf("%I64d %I64d %d", &n, &m, &q);
  while (q--) {
    scanf("%I64d %I64d", &x, &y);
    if ((x & 1) != (y & 1)) {
      printf("-1\n");
      continue;
    }
    if (x == y) {
      printf("%d\n", x);
      continue;
    }
    ans = 1ll << 50;
    ans = min(ans, work(2 * n, x, 2 * m, y));
    ans = min(ans, work(2 * n, 2 * n - x, 2 * m, y));
    ans = min(ans, work(2 * n, x, 2 * m, 2 * m - y));
    ans = min(ans, work(2 * n, 2 * n - x, 2 * m, 2 * m - y));
    if (ans == 1ll << 50)
      printf("-1\n");
    else
      printf("%I64d\n", ans % (n / gcd(n, m) * m));
  }
  return 0;
}
