#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    y = 1;
    x = 0;
    return a;
  } else {
    long long ret = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return ret;
  }
}
long long extend_Euclid(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long r = extend_Euclid(b, a % b, y, x);
  y -= a / b * x;
  return r;
}
long long equation(long long a, long long b, long long c, long long &x,
                   long long &y) {
  long long g = extend_Euclid(a, b, x, y);
  if (c % g == 0) {
    long long mod = b / g;
    x *= c / g;
    if (mod < 0) mod = -mod;
    x = (x % mod + mod) % mod;
    return 0;
  }
  return -1;
}
long long INF;
inline long long doSolve(int dx, int dy) {
  long long k, s;
  if (equation(2 * n, -2 * m, -dx + dy, k, s) == -1) return INF + 1;
  long long tim = 2 * k * n + dx;
  if (tim < 0 || tim > INF) return INF + 1;
  return tim;
}
long long solve(long long x, long long y) {
  long long g = gcd(n, m);
  INF = (long long)m / g * n;
  long long ans = INF + 1;
  ans = min(ans, doSolve(-x, -y));
  ans = min(ans, doSolve(-x, y));
  ans = min(ans, doSolve(x, -y));
  ans = min(ans, doSolve(x, y));
  if (ans == INF + 1) return -1;
  return ans;
}
int main() {
  while (scanf("%d%d%d", &n, &m, &k) != EOF) {
    for (int i = 1; i <= k; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      printf("%I64d\n", solve(x, y));
    }
  }
  return 0;
}
