#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
int sgn(double x) { return (x > EPS) - (x < -EPS); }
inline long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long power(long long x, long long y) {
  long long a = 1;
  for (; y; x = x * x % MOD, y >>= 1)
    if (y & 1) a = a * x % MOD;
  return a;
}
inline long long power(long long x, long long y, long long p) {
  long long a = 1;
  if (y < 0) x = power(x, MOD - 2), y = -y;
  for (; y; x = x * x % p, y >>= 1)
    if (y & 1) a = a * x % p;
  return a;
}
inline long long multi(long long x, long long y, long long p) {
  long long a = 0;
  for (; y; x = x * 2 % p, y >>= 1)
    if (y & 1) a = (a + x) % p;
  return a;
}
inline long long exgcd(long long a, long long b, long long& x, long long& y) {
  if (!b) return x = 1, y = 0, a;
  long long d = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
const int op[2] = {-1, 1};
long long n, m, x0, yy0;
int k;
int main() {
  scanf("%I64d%I64d%d", &n, &m, &k);
  long long d = gcd(n, m);
  long long lim = lcm(n, m);
  long long xx, yy;
  exgcd(n, m, xx, yy);
  for (int i = 1; i <= k; ++i) {
    scanf("%I64d%I64d", &x0, &yy0);
    if (x0 == yy0) {
      printf("%I64d\n", x0);
      continue;
    }
    long long s = 0X3F3F3F3F3F3F3F3F;
    for (int i = 0; i <= 1; ++i)
      for (int j = 0; j <= 1; ++j) {
        long long t = x0 * op[i] + yy0 * op[j];
        if (abs(t) % d != 0) continue;
        t /= d;
        long long x = xx, y = yy;
        x *= t;
        y *= t;
        if (x < 0) {
          long long tmp = (-x) / (m / d);
          if (tmp * (m / d) != (-x)) ++tmp;
          x += 1LL * m / d * tmp;
          y -= 1LL * n / d * tmp;
        }
        if (x >= m / d) {
          long long tmp = x / (m / d);
          x -= 1LL * m / d * tmp;
          y += 1LL * n / d * tmp;
        }
        if (y > 0) {
          long long tmp = y / (n / d);
          if (tmp * (m / d) != y) ++tmp;
          x += 1LL * m / d * tmp;
          y -= 1LL * n / d * tmp;
        }
        if (i == 0 && x == 1) {
          x += 1LL * m / d;
          y -= 1LL * n / d;
        }
        if (j == 0 && y == 0) {
          x += 1LL * m / d;
          y -= 1LL * n / d;
        }
        if (1LL * n * x + 1LL * x0 * op[i ^ 1] ==
            1LL * m * (-1) * y + 1LL * yy0 * op[j]) {
          if (1LL * n * x + 1LL * x0 * op[i ^ 1] < lim)
            if ((x & 1) == 0 && ((-y) & 1) == 0)
              if (1LL * n * x + 1LL * x0 * op[i ^ 1] < s)
                s = 1LL * n * x + 1LL * x0 * op[i ^ 1];
        }
      }
    if (s == 0X3F3F3F3F3F3F3F3F)
      puts("-1");
    else
      printf("%I64d\n", s);
  }
  return 0;
}
