#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
void printDivisors(long long n) {
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        v.push_back(i);
      else {
        v.push_back(i);
        v.push_back(n / i);
      }
    }
  }
}
int main() {
  long long a, b;
  cin >> a >> b;
  long long t;
  cin >> t;
  long long g = GCD(a, b);
  printDivisors(g);
  sort(v.begin(), v.end());
  for (int i = 0; i < t; i++) {
    long long l, u;
    cin >> l >> u;
    vector<long long>::iterator it = lower_bound(v.begin(), v.end(), u);
    if (it == v.end() || *it > u) it--;
    if (*it >= l)
      cout << *it << '\n';
    else
      cout << -1 << '\n';
  }
  return 0;
}
