#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int a, b, n;
  vector<int> div;
  cin >> a >> b >> n;
  if (b > a) swap(a, b);
  for (int d = 1; d * d <= b; d++) {
    if (a % d == 0 and b % d == 0) div.push_back(d);
    int d2 = -1;
    if (b % d == 0 and b / d != d) d2 = b / d;
    if (d2 != -1)
      if (a % d2 == 0) div.push_back(d2);
  }
  sort(div.begin(), div.end());
  while (n--) {
    int l, r;
    cin >> l >> r;
    auto it = upper_bound(div.begin(), div.end(), r);
    it--;
    if (l <= *it and *it <= r)
      cout << *it << endl;
    else
      cout << "-1\n";
  }
}
