#include <bits/stdc++.h>
using namespace std;
long long N, M, K, Ans;
long long m[3], a[3];
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long temp = exgcd(b, a % b, x, y), tmp = x;
  x = y;
  y = tmp - (a / b) * y;
  return temp;
}
long long inv(long long x, long long p) {
  long long x1, y;
  exgcd(x, p, x1, y);
  return x1;
}
bool merge(long long &m0, long long &a0, long long m1, long long a1) {
  long long x, y;
  long long g = exgcd(m0, m1, x, y);
  if ((a1 - a0) % g) return false;
  m1 /= g;
  x *= (a1 - a0) / g;
  x %= m1;
  a0 = (a0 + m0 * x);
  m0 *= m1;
  a0 = (a0 % m0 + m0) % m0;
  return true;
}
long long CRT() {
  long long m0 = 1, a0 = 0;
  for (int i = 1; i <= 2; ++i)
    if (!merge(m0, a0, m[i], a[i])) return 1LL << 61;
  return a0;
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N >> M >> K;
  while (K--) {
    long long x, y, ans = 1LL << 61;
    cin >> x >> y;
    a[1] = x;
    m[1] = 2 * N;
    a[2] = y;
    m[2] = 2 * M;
    ans = min(ans, CRT());
    a[1] = x;
    m[1] = 2 * N;
    a[2] = -y;
    m[2] = 2 * M;
    ans = min(ans, CRT());
    a[1] = -x;
    m[1] = 2 * N;
    a[2] = y;
    m[2] = 2 * M;
    ans = min(ans, CRT());
    a[1] = -x;
    m[1] = 2 * N;
    a[2] = -y;
    m[2] = 2 * M;
    ans = min(ans, CRT());
    if (ans == 1LL << 61)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
