#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
template <class T, class U>
void chmax(T& x, U y) {
  if (x < y) x = y;
}
template <class T, class U>
void chmin(T& x, U y) {
  if (y < x) x = y;
}
template <class T>
void mkuni(V<T>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
struct EG {
  ll g, x, y;
};
EG ext_gcd(ll a, ll b) {
  if (b == 0) {
    if (a >= 0)
      return EG{a, 1, 0};
    else
      return EG{-a, -1, 0};
  } else {
    auto e = ext_gcd(b, a % b);
    return EG{e.g, e.y, e.x - a / b * e.y};
  }
}
pair<ll, ll> crt(const V<ll>& rs, const V<ll>& ms) {
  int N = rs.size();
  ll r = 0, m = 1;
  for (int i = 0; i < int(N); i++) {
    ll ri = rs[i], mi = ms[i];
    auto e = ext_gcd(m, mi);
    ll g = e.g, m_inv = e.x;
    if ((ri - r) % g) return {0, -1};
    ll tmp = (ri - r) / g * m_inv % (mi / g);
    r += m * tmp;
    m *= mi / g;
  }
  return {(r % m + m) % m, m};
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll X, Y;
  int Q;
  cin >> X >> Y >> Q;
  X *= 2, Y *= 2;
  ll inf = 1e18;
  while (Q--) {
    ll ans = inf;
    ll x, y;
    cin >> x >> y;
    for (ll a : {x, X - x}) {
      for (ll b : {y, Y - y}) {
        auto p = crt({a, b}, {X, Y});
        if (p.second != -1) chmin(ans, p.first);
      }
    }
    if (ans == inf)
      cout << -1 << '\n';
    else
      cout << ans << '\n';
  }
}
