#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
long long a, b;
long long g, bg;
long long h1, h2;
int k;
long long extGcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  long long x1, y1;
  long long g = extGcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return g;
}
bool canSolve(long long x1, long long y1) {
  long long s1 = x1 + y1, s2 = x1 - y1;
  if (s1 % 2) return false;
  s1 /= 2, s2 /= 2;
  return s1 % g == 0 or s2 % g == 0;
}
long long solveFor(long long x1, long long y1) {
  long long s = (y1 - x1) / 2;
  if (s % g != 0) return LLONG_MAX;
  long long fh1 = h1 * s / g;
  long long k =
      (long long)ceil((-x1 / double(2 * a) - double(fh1)) / double(bg));
  long long sol = 2 * a * (fh1 + k * bg) + x1;
  return sol;
}
int main() {
  scanf("%lld%lld%d", &a, &b, &k);
  g = extGcd(a, b, h1, h2);
  bg = b / g;
  while (k--) {
    long long x1, y1;
    scanf("%lld%lld", &x1, &y1);
    if (canSolve(x1, y1))
      printf("%lld\n", min(min(solveFor(x1, y1), solveFor(-x1, -y1)),
                           min(solveFor(-x1, y1), solveFor(x1, -y1))));
    else
      printf("-1\n");
  }
  return 0;
}
