#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
void Debug(int i) { printf("\n----Debug %d-----\n", i); }
void Debug(char i) { printf("\n----Debug %c-----\n", i); }
const long long LINF = 1e16;
long long exgcd(long long a, long long b, long long &x, long long &y) {
  long long t = a;
  if (b) {
    t = exgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return t;
}
int xx, yy;
long long solve(int x, int y) {
  long long N = 2 * xx, M = 2 * yy;
  long long first, second;
  long long g = exgcd(N, M, first, second);
  if ((y - x) % g) return LINF;
  long long lcm = N * M / g;
  first *= (y - x) / g;
  long long x0 = first % lcm * N % lcm + x;
  x0 = (x0 % lcm + lcm) % lcm;
  if (x0 == 0) x0 = lcm;
  return x0;
}
int main() {
  int k;
  cin >> xx >> yy >> k;
  long long t = min({solve(xx, yy), solve(0, 0), solve(0, yy), solve(xx, 0)});
  while (k--) {
    long long xxx, yyy;
    cin >> xxx >> yyy;
    long long tt =
        min({solve(xxx, yyy), solve(2 * xx - xxx, yyy),
             solve(xxx, 2 * yy - yyy), solve(2 * xx - xxx, 2 * yy - yyy)});
    if (tt < t && tt < LINF) {
      cout << tt << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
