#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma warning(disable : 1318)
#pragma comment(linker, "/STACK:512000000")
const long long INF = (1ll << 63) - 1ll;
const long double INFd = 28e14;
const int inf = (1 << 31) - 1;
const long double EPS = 1e-8;
const long double PI = acos(-1.0);
const long long mod = 7 + 1e9;
using namespace std;
inline int next_rand() { return abs(rand() * rand() + rand()); }
struct __debug__ {
  __debug__(string filename, bool f = false) {
    if (f) return;
    if (filename == "") return;
    ios_base::sync_with_stdio(0);
    string filein = filename + ".in";
    string fileout = filename + ".out";
    freopen(filein.c_str(), "r", stdin);
    freopen(fileout.c_str(), "w", stdout);
  }
  ~__debug__() {}
};
__debug__ DEBUG("");
void solve();
int main() {
  srand(time(0));
  solve();
}
const int maxk = 100000;
pair<int, int> p[maxk];
long long ans[maxk];
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < k; ans[i] = -1, ++i) cin >> p[i].first >> p[i].second;
  map<pair<int, int>, vector<int> > s, s1, s2, s3, s4;
  for (int a, b, i = 0; i < k; ++i) {
    a = p[i].first - min(p[i].first, p[i].second);
    b = p[i].second - min(p[i].first, p[i].second);
    s1[{a, b}].push_back(i);
    int c = min(m - b, n - a);
    a += c;
    b += c;
    s2[{a, b}].push_back(i);
    a = p[i].first + p[i].second;
    if (a >= n) {
      b = a - n;
      a = n;
    } else {
      b = 0;
    }
    s3[{a, b}].push_back(i);
    b = p[i].first + p[i].second;
    if (b >= m) {
      a = b - m;
      b = m;
    } else {
      a = 0;
    }
    s4[{a, b}].push_back(i);
  }
  pair<int, int> pp(0, 0);
  set<pair<int, int> > used;
  used.insert({0, 0});
  used.insert({n, 0});
  used.insert({0, m});
  used.insert({n, m});
  for (auto i : s1[pp]) {
    ans[i] = min(p[i].first, p[i].second);
  }
  pp.first += min(n, m);
  pp.second += min(n, m);
  bool fx = pp.first != n;
  bool fy = pp.second != m;
  long long tim = pp.first;
  while (true) {
    if (used.find(pp) != used.end()) break;
    used.insert(pp);
    if (pp.first == n) {
      if (fy) {
        for (auto i : s3[pp])
          ans[i] = (ans[i] == -1)
                       ? tim + abs(p[i].first - pp.first)
                       : min(ans[i], tim + abs(p[i].first - pp.first));
        int c = min(m - pp.second, n);
        pp.second += c;
        pp.first -= c;
        fy = pp.second != m;
        fx = pp.first == 0;
        tim += c;
      } else {
        for (auto i : s2[pp])
          ans[i] = (ans[i] == -1)
                       ? tim + abs(p[i].first - pp.first)
                       : min(ans[i], tim + abs(p[i].first - pp.first));
        int c = min(pp.second, n);
        pp.second -= c;
        pp.first -= c;
        fy = pp.second == 0;
        fx = pp.first == 0;
        tim += c;
      }
      continue;
    }
    if (pp.first == 0) {
      if (fy) {
        for (auto i : s1[pp])
          ans[i] = (ans[i] == -1)
                       ? tim + abs(p[i].first - pp.first)
                       : min(ans[i], tim + abs(p[i].first - pp.first));
        int c = min(m - pp.second, n);
        pp.second += c;
        pp.first += c;
        fy = pp.second != m;
        fx = pp.first != n;
        tim += c;
      } else {
        for (auto i : s4[pp])
          ans[i] = (ans[i] == -1)
                       ? tim + abs(p[i].first - pp.first)
                       : min(ans[i], tim + abs(p[i].first - pp.first));
        int c = min(pp.second, n);
        pp.second -= c;
        pp.first += c;
        fy = pp.second == 0;
        fx = pp.first != n;
        tim += c;
      }
      continue;
    }
    if (pp.second == m) {
      fy = false;
      if (fx) {
        for (auto i : s4[pp])
          ans[i] = (ans[i] == -1)
                       ? tim + abs(p[i].first - pp.first)
                       : min(ans[i], tim + abs(p[i].first - pp.first));
        int c = min(n - pp.first, m);
        pp.second -= c;
        pp.first += c;
        fy = pp.second == 0;
        fx = pp.first != n;
        tim += c;
      } else {
        for (auto i : s2[pp])
          ans[i] = (ans[i] == -1)
                       ? tim + abs(p[i].first - pp.first)
                       : min(ans[i], tim + abs(p[i].first - pp.first));
        int c = min(pp.first, m);
        pp.second -= c;
        pp.first -= c;
        fy = pp.second == 0;
        fx = pp.first == 0;
        tim += c;
      }
      continue;
    }
    if (pp.second == 0) {
      fy = true;
      if (fx) {
        for (auto i : s1[pp])
          ans[i] = (ans[i] == -1)
                       ? tim + abs(p[i].first - pp.first)
                       : min(ans[i], tim + abs(p[i].first - pp.first));
        int c = min(n - pp.first, m);
        pp.second += c;
        pp.first += c;
        fy = pp.second != m;
        fx = pp.first != n;
        tim += c;
      } else {
        for (auto i : s3[pp])
          ans[i] = (ans[i] == -1)
                       ? tim + abs(p[i].first - pp.first)
                       : min(ans[i], tim + abs(p[i].first - pp.first));
        int c = min(pp.first, m);
        pp.second += c;
        pp.first -= c;
        fy = pp.second != m;
        fx = pp.first == 0;
        tim += c;
      }
      continue;
    }
  }
  for (int i = 0; i < k; ++i) cout << ans[i] << ' ';
}
