#include <bits/stdc++.h>
using namespace std;
const int _ = 1e2;
const int maxn = 1e5 + _;
inline long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
inline long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  long long tx, ty, d = exgcd(b % a, a, tx, ty);
  x = ty - b / a * tx;
  y = tx;
  return d;
}
long long solve(long long A, long long B, long long K, long long g) {
  if (B < 0) B = -B;
  K = (K % B + B) % B;
  long long x, y, d = exgcd(A, B, x, y);
  if (K % d != 0) return (1LL << 61);
  x *= (K / d);
  long long m = A * (B / d);
  return ((A * x + g) % m + m) % m;
}
int main() {
  long long n, m, Q;
  scanf("%lld%lld%lld", &n, &m, &Q);
  long long L = n / gcd(n, m) * m;
  while (Q--) {
    long long x, y, as = (1LL << 61);
    scanf("%lld%lld", &x, &y);
    as = min(as, solve(2 * n, -2 * m, y - x, x));
    as = min(as, solve(2 * n, -2 * m, m + m - y - x, x));
    as = min(as, solve(2 * n, -2 * m, -n - n + y + x, 2 * n - x));
    as = min(as, solve(2 * n, -2 * m, -n - n + m + m - y + x, 2 * n - x));
    if (as > L)
      puts("-1");
    else
      printf("%lld\n", as);
  }
  return 0;
}
