#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.push_back(x);
  return v;
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << "[DEBUG] " << it->substr((*it)[0] == ' ', it->length()) << " = " << a
       << '\n';
  err(++it, args...);
}
const int MOD = 1000000007;
template <class T, class U>
inline T tmin(T a, U b) {
  return (a < b) ? a : b;
}
template <class T, class U>
inline T tmax(T a, U b) {
  return (a > b) ? a : b;
}
template <class T, class U>
inline void amax(T &a, U b) {
  if (b > a) a = b;
}
template <class T, class U>
inline void amin(T &a, U b) {
  if (b < a) a = b;
}
template <class T>
inline T tabs(T a) {
  return (a > 0) ? a : -a;
}
template <class T>
T gcd(T a, T b) {
  while (b != 0) {
    T c = a;
    a = b;
    b = c % b;
  }
  return a;
}
const long long INF = (long long)1e18;
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
inline long long solve(long long Zn, long long Zm, long long Zd, long long x,
                       long long y) {
  long long z = abs(x - y);
  if (z % Zd != 0)
    return -1;
  else {
    long long w = (x - y) / Zd, s, t;
    extgcd(Zn, Zm, s, t);
    s *= w, t *= -w;
    long long dZn = Zn / Zd, dZm = Zm / Zd;
    long long r = (s * Zn + y - 1) / (dZm * Zn);
    while ((s - r * dZm) * Zn + y < 1) r--;
    while (1) {
      if ((s - r * dZm) * Zn + y >= 1)
        r++;
      else {
        r--;
        break;
      }
    }
    if (r > s / dZm) amin(r, s / dZm);
    if (r > t / dZn) amin(r, t / dZn);
    s = s - r * dZm;
    t = t - r * dZn;
    long long diff = s * Zn + y - (t * Zm + x);
    return (s * Zn + y);
  }
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  int n, m, k, x, y;
  cin >> m >> n >> k;
  int d = gcd(m, n);
  long long max_time = m * 1LL * n / d;
  int Zn = n * 2, Zm = m * 2, Zd = d * 2;
  for (int _ = (0); _ < (k); ++_) {
    cin >> x >> y;
    if (n == m) {
      printf("%d\n", x == y ? x : -1);
    } else if (x == y)
      printf("%d\n", x);
    else {
      long long ans = max_time + 1;
      long long tmp = solve(Zn, Zm, Zd, x, y);
      if (tmp != -1) amin(ans, tmp);
      tmp = solve(Zn, Zm, Zd, -x, -y);
      if (tmp != -1) amin(ans, tmp);
      tmp = solve(Zn, Zm, Zd, x, -y);
      if (tmp != -1) amin(ans, tmp);
      tmp = solve(Zn, Zm, Zd, -x, y);
      if (tmp != -1) amin(ans, tmp);
      if (ans > max_time) ans = -1;
      printf("%lld\n", ans);
    }
  }
  return 0;
}
