#include <bits/stdc++.h>
using namespace std;
long long n, m, k, ans, last, d, x, y, a, b;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {
  if (!b) {
    x = 1, y = 0, d = a;
  } else {
    exgcd(b, a % b, d, y, x);
    y -= (a / b) * x;
  }
}
void check(long long x0, long long y0) {
  exgcd(a, b, d, x, y);
  if ((y0 - x0) % d != 0) return;
  long long tmp = abs(b / d);
  x *= (y0 - x0) / d;
  x = (x % tmp + tmp) % tmp;
  long long xx = x0 + 2 * n * x;
  if (xx < 0 || xx >= last) return;
  ans = min(ans, xx);
}
int main() {
  cin >> n >> m >> k;
  a = 2 * n, b = -2 * m;
  while (k--) {
    long long xx, yy;
    cin >> xx >> yy;
    ans = 1e18;
    last = n / gcd(n, m) * m;
    check(xx, yy);
    check(-xx, yy);
    check(xx, -yy);
    check(-xx, -yy);
    if (ans == 1e18)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}
