#include <bits/stdc++.h>
using namespace std;
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    long long res = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return res;
  }
}
long long n, m, x, y, t, _lcm, res, dx, dy;
long long cal(long long tx, long long ty) {
  long long tmp = ty - tx;
  long long _gcd = exgcd(2 * n, -2 * m, dx, dy);
  if (tmp % _gcd) return 2e18;
  long long mod = -2 * m / _gcd;
  tmp = tmp / _gcd;
  if (mod < 0) mod = -mod;
  long long ans = (dx * tmp % mod + mod) % mod;
  ans = ans * 2 * n + tx;
  if (ans >= _lcm || ans <= 0) return 2e18;
  return ans;
}
int main() {
  scanf("%lld %lld %lld", &n, &m, &t);
  _lcm = n * m / exgcd(n, m, x, y);
  while (t--) {
    res = 2e18;
    scanf("%lld %lld", &x, &y);
    res = min(res, cal(x, y));
    res = min(res, cal(-x, y));
    res = min(res, cal(x, -y));
    res = min(res, cal(-x, -y));
    if (res == 2e18) res = -1;
    printf("%lld\n", res);
  }
}
