#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <numeric>
#include <limits.h>
#include <iterator>
#include <iomanip>
#define REP(x,n)  for(x=0;x<(int)(n);x++)

using namespace std;

#define REP(x,n)  for(x=0;x<(int)(n);x++)
#define EACH(itr, cont) for(typeof((cont).begin()) itr = (cont).begin(); itr != (cont).end(); ++itr)
#define ALL(X)    (X).begin(),(X).end()

typedef long long LL;

int main(int argc, char** argv) {
    cin.sync_with_stdio(false);
    cout << setprecision(16);
    int t, i;
    double a, b;
    cin >> t;

    REP(i, t) {
        // p->[0,a] , q->[-b,b]
        cin >> a >> b;
        double result = 0;
        if (b == 0) {
            result = 1;
        } else if (a == 0) {
            result = 0;
        } else {
            double c = 4 * b, total = 2.0 * c*a;
            result = 0.5;
            result += min(a, c) * min(a, c) / 2 / total;
            if (a > c) {
                result += (a - b) * b / total;
            }
        }

        cout << result;
    }
}


#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <numeric>
#include <limits.h>
#include <iterator>
#include <iomanip>
#define REP(x,n)  for(x=0;x<(int)(n);x++)

using namespace std;

#define REP(x,n)  for(x=0;x<(int)(n);x++)
#define EACH(itr, cont) for(typeof((cont).begin()) itr = (cont).begin(); itr != (cont).end(); ++itr)
#define ALL(X)    (X).begin(),(X).end()

typedef long long LL;

int main(int argc, char** argv) {
    cin.sync_with_stdio(false);
    cout << setprecision(16);
    int t, i;
    double a, b;
    cin >> t;

    REP(i, t) {
        // p->[0,a] , q->[-b,b]
        cin >> a >> b;
        double result = 0;
        if (b == 0) {
            result = 1;
        } else if (a == 0) {
            result = 0;
        } else {
            double c = 4 * b, total = 2.0 * c*a;
            result = 0.5;
            result += min(a, c) * min(a, c) / 2 / total;
            if (a > c) {
                result += (a - c) * c / total;
            }
        }

        cout << result << endl;
    }
}


#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <numeric>
#include <limits.h>
#include <iterator>
#include <iomanip>
#define REP(x,n)  for(x=0;x<(int)(n);x++)

using namespace std;

#define REP(x,n)  for(x=0;x<(int)(n);x++)
#define EACH(itr, cont) for(typeof((cont).begin()) itr = (cont).begin(); itr != (cont).end(); ++itr)
#define ALL(X)    (X).begin(),(X).end()

typedef long long LL;

int main(int argc, char** argv) {
    cin.sync_with_stdio(false);
    cout << setprecision(16);
    int t, i;
    double a, b;
    cin >> t;

    REP(i, t) {
        // p->[0,a] , q->[-b,b]
        cin >> a >> b;
        double result = 0;
        if (b == 0) {
            result = 1;
        } else if (a == 0) {
            result = 0;
        } else {
            double c = 4 * b, total = 2.0 * c*a;
            result = 0.5;
            result += min(a, c) * min(a, c) / 2 / total;
            if (a > c) {
                result += (a - b) * b / total;
            }
        }

        cout << result << endl;
    }
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORT(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define VI(i) vector<i>
using namespace std;
/*typedef struct node
{
int data;
node *next;
}mynode;
mynode *head;*/

int main()
{
int t;
cin>>t;
float a,b;
while(t--)
{
          float val;
          cin>>a>>b;
         if(a<(4*b))
         {val=4*b*a+(a*a/2);
         val/=(8*b*a);
         }
         else
         {
             val=4*b*a+(2*b*(2*a-4*b));
             val/=(8*b*a);

             }
             cout<<val<<endl;
}
//system("pause");
return 0;
}


    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <string>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <cstdio>
   #include <cstdlib>
   #include <cctype>
   #include <cmath>
   #define FOR(i,n) for(int i=0;i<n;i++)
   #define FORT(i,a,b) for(int i=a;i<b;i++)
   #define FORR(i,n) for(int i=n;i>=0;i--)
   #define MAX(a,b) a>b?a:b
   #define MIN(a,b) a<b?a:b
   #define VI(i) vector<i>
   using namespace std;
   /*typedef struct node
  21. {
  22. int data;
  23. node *next;
  24. }mynode;
  25. mynode *head;*/

   int main()
   {
   int t;
   cin>>t;
   double a,b;
   while(t--)
   {
             double val;
             cin>>a>>b;
            if(a<(4*b))
            {val=4*b*a+(a*a/2);
            val/=(8*b*a);
            }

            else
            {
                if(b==0)val=1;
                else{
                val=4*b*a+(2*b*(2*a-4*b));
                val/=(8*b*a);
                }

                }
                cout<<val<<endl;
   }
   //system("pause");
   return 0;
   }


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORT(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define VI(i) vector<i>
using namespace std;
/*typedef struct node
{
int data;
node *next;
}mynode;
mynode *head;*/

int main()
{
int t;
cin>>t;
float a,b;
while(t--)
{
          float val;
          cin>>a>>b;
         if(a<(4*b))
         {
         if(a==0)val=0.5;
         else{
         val=4*b*a+(a*a/2);
         val/=(8*b*a);
         }}

         else
         {
             if(b==0)val=1;
             else{
             val=4*b*a+(2*b*(2*a-4*b));
             val/=(8*b*a);
             }

             }
             cout<<val<<endl;
}
//system("pause");
return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORT(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define VI(i) vector<i>
using namespace std;
/*typedef struct node
{
int data;
node *next;
}mynode;
mynode *head;*/

int main()
{
int t;
cin>>t;
float a,b;
while(t--)
{
          cin>>a>>b;
          float val=0.5+(0.25*0.25*(a/b));
          cout<<val<<endl;

          }
//system("pause");
return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORT(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define VI(i) vector<i>
using namespace std;
/*typedef struct node
{
int data;
node *next;
}mynode;
mynode *head;*/

int main()
{
int t;
cin>>t;
float a,b;
while(t--)
{
          float val;
          cin>>a>>b;
         if(a<(4*b))
         {val=4*b*a+(a*a/2);
         val/=(8*b*a);
         }

         else
         {
             if(b==0)val=1;
             else{
             val=4*b*a+(2*b*(2*a-4*b));
             val/=(8*b*a);
             }

             }
             cout<<val<<endl;
}
//system("pause");
return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORT(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define VI(i) vector<i>
using namespace std;
/*typedef struct node
{
int data;
node *next;
}mynode;
mynode *head;*/

int main()
{
int t;
cin>>t;
float a,b;
while(t--)
{
          cin>>a>>b;
          float val;
          if(b!=0)
          val=0.5+(0.25*0.25*(a/b));
          else  val=(0.25*0.25*(a/b));
          cout<<val<<endl;

          }
//system("pause");
return 0;
}


/*
ID:1192432
PROG: castle
LANG: C++
*/
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX=100,INF=1<<30;

int main()
{
   // freopen("i.txt","r",stdin);
    //freopen("castle.in","r",stdin);
    //freopen("castle.out","w",stdout);
    int n;
    double a,b,x,y;
    cin>>n;
    while(n--){
        cin>>a>>b;
        if(4*b>a)
            cout<<((2*b*a)-((b-a/4)+b)*a/2)/(2*b*a);
        else
            cout<<((2*b*a)-(b*4*b)/2)/(2*b*a);
        cout<<endl;
    }
    return 0;
}


/*
ID:1192432
PROG: castle
LANG: C++
*/
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX=100,INF=1<<30;

int main()
{
   // freopen("i.txt","r",stdin);
    //freopen("castle.in","r",stdin);
    //freopen("castle.out","w",stdout);
    int n;
    double a,b,t;
    cin>>n;
    while(n--){
        cin>>a>>b;
        if(!b||!a){
            t=1;
            goto ans;
        }
        if(4*b>a)
            t=((2*b*a)-((b-a/4)+b)*a/2)/(2*b*a);
        else
            t=((2*b*a)-(b*4*b)/2)/(2*b*a);
ans:
        printf("%.10lf\n",t);
    }
    return 0;
}


/*
ID:1192432
PROG: castle
LANG: C++
*/
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX=100,INF=1<<30;

int main()
{
    //freopen("i.txt","r",stdin);
    //freopen("castle.in","r",stdin);
    //freopen("castle.out","w",stdout);
    int n;
    double a,b,t;
    cin>>n;
    while(n--){
        cin>>a>>b;
        if(!b){
            t=1;
            goto ans;
        }
        if(4*b>a)
            t=((2*b*a)-((b-a/4)+b)*a/2)/(2*b*a);
        else
            t=((2*b*a)-(b*4*b)/2)/(2*b*a);
ans:
        printf("%.10lf\n",t);
    }
    return 0;
}


/*
ID:1192432
PROG: castle
LANG: C++
*/
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX=100,INF=1<<30;

int main()
{
    //freopen("i.txt","r",stdin);
    //freopen("castle.in","r",stdin);
    //freopen("castle.out","w",stdout);
    int n;
    double a,b,t;
    cin>>n;
    while(n--){
        cin>>a>>b;
        if(4*b>a)
            t=((2*b*a)-((b-a/4)+b)*a/2)/(2*b*a);
        else
            t=((2*b*a)-(b*4*b)/2)/(2*b*a);
        printf("%.10lf\n",t);
    }
    return 0;
}


/*
ID:1192432
PROG: castle
LANG: C++
*/
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX=100,INF=1<<30;

int main()
{
   // freopen("i.txt","r",stdin);
    //freopen("castle.in","r",stdin);
    //freopen("castle.out","w",stdout);
    int n;
    double a,b,t;
    cin>>n;
    while(n--){
        cin>>a>>b;
        if(!b){
            t=1;
            goto ans;
        }
        if(!a){
            t=0.5;
            goto ans;
        }
        if(4*b>a)
            t=((2*b*a)-((b-a/4)+b)*a/2)/(2*b*a);
        else
            t=((2*b*a)-(b*4*b)/2)/(2*b*a);
ans:
        printf("%.10lf\n",t);
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define exp 1e-6
int dblcmp(double x)
{
    if(x > -exp && x < exp)
        return 0;
    return x > 0 ? 1 : -1;
}
int main()
{
    int t;
    double a, b;
    scanf("%d", &t);
    while(t--){
        scanf("%lf %lf", &a, &b);
        if(!dblcmp(b))
            printf("1.000000\n");
        else printf("%lf\n", (2 * b + a / 4) / (4 * b));
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define exp 1e-9
int dblcmp(double x)
{
    if(x > -exp && x < exp)
        return 0;
    return x > 0 ? 1 : -1;
}
int main()
{
    int t;
    double a, b;
    scanf("%d", &t);
    while(t--){
        scanf("%lf %lf", &a, &b);
        if(!dblcmp(b))
            printf("1\n");
        else printf("%lf\n", (2 * b + a / 4) / 4 / b);
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define exp 1e-6
int dblcmp(double x)
{
    if(x > -exp && x < exp)
        return 0;
    return x > 0 ? 1 : -1;
}
int main()
{
    int t;
    double a, b;
    scanf("%d", &t);
    while(t--){
        scanf("%lf %lf", &a, &b);
        if(!dblcmp(b))
            printf("1.0000000000\n");
        else printf("%.10lf\n", (2 * b + a / 4) / (4 * b));
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define exp 1e-10
int dblcmp(double x)
{
    if(x > -exp && x < exp)
        return 0;
    return x > 0 ? 1 : -1;
}
int main()
{
    int t;
    double a, b;
    scanf("%d", &t);
    while(t--){
        scanf("%lf %lf", &a, &b);
        if(!dblcmp(b))
            printf("1\n");
        else if(!dblcmp(a))
            printf("0.5\n");
        else {
            if(dblcmp(a / 4 - b) <= 0)
                printf("%lf\n", (2 * b + a / 4) / (4 * b));
            else printf("%lf\n", (a - b) / a);
        }
    }
    return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4*b) + ((4*b)))/2)
	     /((double)2*a));
    }
    else {
      res = ((double)(a))/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    //cout << res << "\n";
    printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
int a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a == 0);
    else if((a/4.0) > b) {
       res = ((double)(a-2*b)
             /((double)2*a));
    }
    else {
      res = (double)(a)/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    cout << res << "\n";
    //printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if((a/4.0) > b) {
       res = ((double)(a-2*b)
             /((double)2*a));
    }
    else {
      res = (double)(a)/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    cout << res << "\n";
    //printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4*b) + (a-(a-4*b)))/2)
	/((double)2*a);
    }
    else {
      res = ((double)(a/8.0))/((double)b/2.0);// * (1.0/16.0);
    }
    res += 0.5;
    //cout << res << "\n";
    printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4*b) + ((a-(a-4*b)))/2)
             /((double)2*a));
    }
    else {
      res = (double)(a)/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    cout << res << "\n";
    //printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if((a/4.0) > b) {
      //res = ((double)((a-4*b) + (4*b))/2)
      //     /((double)2*a));
      res = a/4.0;
    }
    else {
      res = (double)(a)/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    cout << res << "\n";
    //printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
int a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res=0.0;
    if(a == 0 && b == 0) res = 0.5;
    else if(a== 0) res = 0.0;
    else if((a/4.0) > b) {
       res = ((double)(a-2*b)
             /((double)2*a));
    }
    else {
      res = (double)(a)/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    cout << res << "\n";
    //printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4*b) + (a-(a-4*b)))/2)
	/((double)2*a);
    }
    else {
      res = ((double)(a))/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    //cout << res << "\n";
    printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)(a*b + (a-4.0*b)*b + ((a-(a-4.0*b))*b)/2.0)
	     /((double)2.0*a*b));
    }
    else {
      res = ((double)(a*b + a*a/8.0))/((double)2.0*a*b);
    }
    cout << res << "\n";
    //printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4*b) + ((4*b)))/2)
	     /((double)2*a);
    }
    else {
      res = ((double)(a))/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    //cout << res << "\n";
    printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
int a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    scanf("%d %d",&a,&b);
    double res;
    if(a/4.0 > b) {
      res = ((double)(a*b + (a-4.0*b)*b + ((a-(a-4.0*b))*b)/2.0)
	     /((double)2.0*a*b));
    }
    else {
      res = ((double)(a*b + a*a/8.0))/((double)2.0*a*b);
    }
      printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4*b) + (4*b))/2)
	/((double)2*a);
    }
    else {
      res = ((double)(a)/((double)b); * (1.0/16.0);
    }
    res += 0.5;
    //cout << res << "\n";
    printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
int a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res=0.0;
    if(a == 0);
    else if((a/4.0) > b) {
       res = ((double)(a-2*b)
             /((double)2*a));
    }
    else {
      res = (double)(a)/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    cout << res << "\n";
    //printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
int a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if((a/4.0) > b) {
       res = ((double)(a-2*b)
             /((double)2*a));
    }
    else {
      res = (double)(a)/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    cout << res << "\n";
    //printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4.0*b) + ((a-(a-4.0*b)))/2.0)
	     /((double)2.0*a));
    }
    else {
      res = ((double)(a/8.0))/((double)2.0*b);
    }
    res += 0.5;
    //cout << res << "\n";
    printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)(a*b + (a-4.0*b)*b + ((a-(a-4.0*b))*b)/2.0)
	     /((double)2.0*a*b));
    }
    else {
      res = ((double)(a*b + a*a/8.0))/((double)2.0*a*b);
    }
      printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4*b) + ((a-(a-4*b)))/2)
             /((double)2*a));
    }
    else {
      res = (double)(a)/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    //cout << res << "\n";
    printf("%.9lf\n",res);
}

  return 0;
}


//Tadrion
#include <cstdio>
#include <vector>
#include <iostream>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
using namespace std;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define CLEAR(x) (memset(x,0,sizeof(x)))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define VAR(v, n) __typeof(n) v = (n)
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define DBG(v) cout<<#v<<" = "<<v<<endl;
#define IN(x,y) ((y).find(x)!=(y).end())
#define ST first
#define ND second
#define PB push_back
#define PF push_front
typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
int t;
LL a,b;
int main() {
  scanf("%d",&t);
  for(int i = 0; i < t; i++) {
    //scanf("%d %d",&a,&b);
    cin >> a >> b;
    double res;
    if(a/4.0 > b) {
      res = ((double)((a-4*b) + ((a-(a-4*b)))/2)
	     /((double)2*a));
    }
    else {
      res = ((double)(a))/((double)b) * (1.0/16.0);
    }
    res += 0.5;
    //cout << res << "\n";
    printf("%.9lf\n",res);
}

  return 0;
}


# include <stdio.h>
int main ()
{
	double a,b;
	double s;
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%llf %llf",&a,&b);
	if(a==0)
		printf("0.5\n");
	else
	{if(a>=4*b)
	{
		s=4*(double)b*4*b/2;
	}
	else
	{
		s=a*a/2+(4*b-a)*a;
	}
	//printf("%llf\n",s);
	printf("%llf\n",(a*8*b-s)/(a*8*b));
	}
	}
	return 0;
}


# include <stdio.h>
int main ()
{
	int a,b;
	double s;
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d",&a,&b);
	if(a==0)
		printf("0.5\n");
	else
	{if(a>=4*b)
	{
		s=4*(double)b*4*b/2;
	}
	else
	{
		s=(double)a*a/2+(4*(double)b-(double)a)*(double)a;
	}
	//printf("%llf\n",s);
	printf("%llf\n",(double)((double)a*8*b-s)/(double)(a*8*b));
	}
	}
	return 0;
}


# include <stdio.h>
int main ()
{
    double a,b;
    double s;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf %lf",&a,&b);
        if(a==0&&b!=0)
            printf("0.5\n");
        else if(b==0)
        {
            printf("1\n");
        }
        else
        {
            if(a>=4*b)
            {
            s=4*b*4*b/2;
            }
            else
            {
                s=a*a/2+(4*b-a)*a;
            }
            printf("%llf\n",(a*8*b-s)/(a*8*b));
        }
    }
    return 0;
}


# include <stdio.h>
int main ()
{
	double a,b;
	double s;
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%llf %llf",&a,&b);
		if(a==0)
			printf("0.5\n");
		else
		{if(a>=4*b)
		{
			s=4*b*4*b/2;
		}
		else
		{
			s=a*a/2+(4*b-a)*a;
		}
		printf("%llf\n",(a*8*b-s)/(a*8*b));
		}
	}
	return 0;
}


# include <stdio.h>
int main ()
{
	int a,b;
	double s;
	int T;
	scanf("%d",&t);
	while(T--)
	{
		scanf("%d %d",&a,&b);
	if(a==0)
		printf("0.5\n");
	else
	{if(a>=4*b)
	{
		s=4*(double)b*4*b/2;
	}
	else
	{
		s=(double)a*a/2+(4*(double)b-(double)a)*(double)a;
	}
	//printf("%llf\n",s);
	printf("%llf\n",(double)((double)a*8*b-s)/(double)(a*8*b));
	}
	}
	return 0;
}


# include <stdio.h>
int main ()
{
	double a,b;
	double s;
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%llf %llf",&a,&b);
		if(a==0&&b!=0)
			printf("0.5\n");
		else if(b==0)
		{
			printf("1\n");
		}
		else
		{
			if(a>=4*b)
			{
			s=4*b*4*b/2;
			}
			else
			{
				s=a*a/2+(4*b-a)*a;
			}
			printf("%llf\n",(a*8*b-s)/(a*8*b));
		}
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        double a,b;
        cin>>a>>b;
        double res= 0.5;
        if(a>4*b){
            double ds;
            if(a!=0)ds=4*b/a;
            else ds=1;

            double q=1-ds;
            double dw=ds/2.0+q;
            res+=0.5*dw;
        }
        else {
            if(b!=0) res+=0.5*((a/4)/b)*0.5;
            else res +=0.5;
        }
        printf("%.10lf\n", res);
    }

}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        double a,b;
        cin>>a>>b;
        double res= 0.5;
        if(a>4*b){
            double ds;
            if(a!=0)ds=4*b/a;
            else ds=1;

            double q=1-ds;
            double dw=ds/2.0+q;
            res+=0.5*dw;
        }
        else {
            if(b!=0) res+=0.5*((a/4)/b)*0.5;
            else res =0.5*0.5;
        }
        printf("%.10lf\n", res);
    }

}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        double a,b;
        cin>>a>>b;
        double res= 0.5;
        if(a>4*b){
            double ds=4*b/a;
            double q=1-ds;
            double dw=ds/2.0+q;
            res+=0.5*dw*0.5;
        }
        else res+=0.5*((a/4)/b)*0.5;
        printf("%.10lf\n", res);
    }

}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        double a,b;
        cin>>a>>b;
        double res= 0.5;
        res+=0.5*((a/4)/b)*0.5;
        printf("%.10lf\n", res);
    }

}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        double a,b;
        cin>>a>>b;
        double res= 0.5;
        if(a>4*b){
            double ds=4*b/a;
            double q=1-ds;
            double dw=ds/2.0+q;
            res+=0.5*dw;
        }
        else res+=0.5*((a/4)/b)*0.5;
        printf("%.10lf\n", res);
    }

}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        double a,b;
        cin>>a>>b;
        double res= 0.5;
        if(a>4*b){
            double ds;
            if(a!=0)ds=4*b/a;
            else ds=1;

            double q=1-ds;
            double dw=ds/2.0+q;
            res+=0.5*dw;
        }
        else res+=0.5*((a/4)/b)*0.5;
        printf("%.10lf\n", res);
    }

}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define vc vector
#define fr(i,n) for(int i=0; i<n; i++)

int a,b,n;
int main() {
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	cin >> n;
	fr(i,n) {
		cin >> a>>b;
		printf("%.10f\n" , 0.5+(a*1.0)/(b*16.0) + 1e-9);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define vc vector
#define fr(i,n) for(int i=0; i<n; i++)

int a,b,n;
int main() {
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	cin >> n;
	fr(i,n) {
		cin >> a>>b;
		if (b==0)printf("%.10f\n" , 1.0); else
		printf("%.10f\n" , 0.5+(a*1.0)/(b*16.0) + 1e-9);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define vc vector
#define fr(i,n) for(int i=0; i<n; i++)

int a,b,n;
int main() {
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	cin >> n;
	fr(i,n) {
		cin >> a>>b;
		if (b==0)printf("%.10f\n" , 1.0); else
		if (a/4.0>b) {
			printf("%.10f\n",0.5+(0.5-(b*1.0)/(a*1.0)));
		} else
		printf("%.10f\n" , 0.5+(a*1.0)/(b*16.0) + 1e-9);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define vc vector
#define fr(i,n) for(int i=0; i<n; i++)

int a,b,n;
int main() {
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	cin >> n;
	fr(i,n) {
		cin >> a>>b;
		printf("%.10f\n" , 0.5+(a*1.0)/(b*16.0));
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define vc vector
#define fr(i,n) for(int i=0; i<n; i++)

int a,b,n;
int main() {
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	cin >> n;
	fr(i,n) {
		cin >> a>>b;
		if (b==0)printf("%.10f\n" , 1.0); else
		if (a/4.0>b) {
			printf("%.10f\n",0.5+(a-4.0*b)/(2.0*a));
		} else
		printf("%.10f\n" , 0.5+(a*1.0)/(b*16.0) + 1e-9);
	}
	return 0;
}


#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {
        int a,b;
        cin >> a;
        cin >> b;
        if (b==0)
        {
            cout << 0 << endl;
            continue;
        }
        double res;
        if(a<4*b)
        {
            res=a*b+(double)(a*a)/8;
            res/=(2*a*b);
        }
        else
        {
            res=2*a*b;
            res-=(2*b*b);
            res/=(2*a*b);
        }
        cout << res << endl;
    }
    return 0;
}


#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {
        int a,b;
        cin >> a;
        cin >> b;
        if (b==0)
        {
            cout << 1 << endl;
            continue;
        }
        if (a==0)
        {
            cout << 0 << endl;
            continue;
        }
        double res;
        if(a<4*b)
        {
            res=b+(double)(a)/8;
            res/=(2*b);
        }
        else
        {
            res=a;
            res-=b;
            res/=a;
        }
        cout << res << endl;
    }
    return 0;
}


#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {
        double a,b;
        cin >> a;
        cin >> b;
        if (b==0)
        {
            cout << 1.0 << endl;
            continue;
        }
        if (a==0)
        {
            cout << 0.5 << endl;
            continue;
        }
        double res;
        if(a<4*b)
        {
            res=b+a/8.0;
            res/=(2.0*b);
        }
        else
        {
            res=a;
            res-=b;
            res/=a;
        }
        cout << res << endl;
    }
    return 0;
}


#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {
        double a,b;
        cin >> a;
        cin >> b;
        if (b==0)
        {
            cout << 1 << endl;
            continue;
        }
        if (a==0)
        {
            cout << 0 << endl;
            continue;
        }
        double res;
        if(a<4*b)
        {
            res=b+a/8.0;
            res/=(2.0*b);
        }
        else
        {
            res=a;
            res-=b;
            res/=a;
        }
        cout << res << endl;
    }
    return 0;
}


#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {
        double a,b;
        cin >> a;
        cin >> b;
        if (b==0)
        {
            cout << 1.0 << endl;
            continue;
        }
        if (a==0)
        {
            cout << 0.0 << endl;
            continue;
        }
        double res;
        if(a<4*b)
        {
            res=b+a/8.0;
            res/=(2.0*b);
        }
        else
        {
            res=a;
            res-=b;
            res/=a;
        }
        cout << res << endl;
    }
    return 0;
}


// Thaon Toncien

#include <iostream>
#include <cstdio>

using namespace std;

typedef long double real;

int a, b;
real ANS;

inline void EXEC()
{
	cin >> a >> b;
	if (b * 4 <= a) {
		ANS = ((real)b * b * 2) / ((real)a * b * 2);
	} else {
		ANS = ((real)a * b - (real)a * a / 8) / ((real)a * b * 2);
	}

	cout << 1 - ANS << endl;
}

int main()
{
	int t; scanf("%d", &t);
	while (t--)
		EXEC();
	return 0;
}


// Thaon Toncien

#include <iostream>
#include <cstdio>

using namespace std;

typedef long double real;

int a, b;
real ANS;

inline void EXEC()
{
	cin >> a >> b;

	if (a == 0 && b == 0) {
		cout << "1.0" << endl;
		return;
	}

	if (a == 0) {
		cout << "0.5" << endl;
		return;
	} else if(b == 0) {
		cout << "1.0" << endl;
		return;
	}

	if (b * 4 <= a) {
		ANS = ((real)b * b * 2) / ((real)a * b * 2);
	} else {
		ANS = ((real)a * b - (real)a * a / 8) / ((real)a * b * 2);
	}

	cout << 1 - ANS << endl;
}

int main()
{
	int t; scanf("%d", &t);
	while (t--)
		EXEC();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    vector<ll>factors;
    for(ll i=1; i<=min(gc,100000000LL); i++)
    {
        if(a%i==0 && b%i==0)
        {
            factors.push_back(i);
        }
    }
    //for(vector<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    ll szFactors=factors.size();
    //cout<<szFactors<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll low=0,high=szFactors-1,mid,ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            if(factors[mid]>=l && factors[mid]<=h)
            {
                ans=mid;
                low=mid+1;
            }
            else if(factors[mid]<l)
            {
                low=mid+1;
            }
            else if(factors[mid]>h)
            {
                high=mid-1;
            }

        }
        if(ans>=szFactors || ans<0)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<factors[ans]<<endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    set<ll>factors;
    for(ll i=1; i<=min(gc,20LL); i++)
    {
        if(a%i==0 && b%i==0)
        {
            factors.insert(i);
            ll x = a /  i;
            ll y = b / i;
            //cout<<i<<" "<<x<<" "<<y<<endl;

            if(a % x == 0 && b % x == 0)
            {
                factors.insert(x);
            }
            if(a % y == 0 && b % y == 0)
            {
                factors.insert(y);
            }
        }
    }
    //for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    vector<ll>vt;
    for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) vt.push_back(*it);
    ll szvt=vt.size();
    //cout<<szFactors<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll low=0,high=szvt-1,mid,ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            //cout<<low<<" "<<high<<" "<<mid<<endl;
            if(vt[mid]>=l && vt[mid]<=h)
            {
                ans=mid;
                low=mid+1;
            }
            else if(vt[mid]<l)
            {
                low=mid+1;
            }
            else if(vt[mid]>h)
            {
                high=mid-1;
            }

        }
        if(ans>=szvt || ans<0)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<vt[ans]<<endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool isDivisable(ll a,ll b,ll predictDivisor)
{
    if(a%predictDivisor==0 && b%predictDivisor==0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main()
{
    ll a,b;
    cin>>a>>b;
    ll lcf=1;
    ll tmp=min(a,b);
    ll limit=sqrt(tmp)+1;
    for(ll i=2; i<=limit; i++)
    {
        if(a%i==0 && b%i==0)
        {
            lcf=i;
            break;
        }
    }
    //cout<<lcf<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll low,high;
        cin>>low>>high;
        ll p=0;
        ll sz=(high-low)+1;
        ll x[sz+5];
        for(ll k=low; k<=high; k++)
        {
            x[p++]=k;
        }
//        for(ll p=0; p<sz; p++)
//        {
//            cout<<x[p]<<" ";
//        }
        ll ans=-1;
        ll l=0,h=sz-1,m;
        //cout<<l<<" "<<h<<endl;
        while(l<=h)
        {
            //cout<<"b"<<endl;
            m=(l+h)/2;
            //cout<<l<<" "<<h<<" "<<m<<endl;
            if(m<0 || m>=sz)
            {
                break;
            }
            if(isDivisable(a,b,x[m])==true)
            {
                ans=x[m];
                l=m+1;
            }
            else if(x[m]>lcf)
            {
                h=m-1;
            }
            else
            {
                l=m+1;
            }
//            cout<<l<<" "<<h<<" "<<m<<endl;
//            cout<<"------------------------------"<<endl;
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=__gcd(a,b);
    ll limit=sqrt(gc)+1;
    vector<ll>factors;
    for(ll i=1; i<=limit; i++)
    {
        if(gc%i==0)
        {
            factors.push_back(i);
            factors.push_back(gc/i);
        }
    }
    sort(factors.begin(),factors.end());
    ll sz=factors.size();
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll low=0,high=sz-1,mid,ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            //cout<<low<<" "<<high<<" "<<mid<<endl;
            if(factors[mid]>=l && factors[mid]<=h)
            {
                ans=mid;
                low=mid+1;
            }
            else if(factors[mid]<l) low=mid+1;
            else if(factors[mid]>h) high=mid-1;
        }
        if(ans>=sz || ans<0) cout<<"-1"<<endl;
        else cout<<factors[ans]<<endl;
    }
    return 0;
}

/*
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    set<ll>factors;
    for(ll i=1; i<=min(gc,100000000LL); i++)
    {
        if(a%i==0 && b%i==0)
        {
            factors.insert(i);
            ll x = a /  i;
            ll y = b / i;
            //cout<<i<<" "<<x<<" "<<y<<endl;

            if(a % x == 0 && b % x == 0)
            {
                factors.insert(x);
            }
            if(a % y == 0 && b % y == 0)
            {
                factors.insert(y);
            }
        }
    }
    //for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    vector<ll>vt;
    for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) vt.push_back(*it);
    ll szvt=vt.size();
    //cout<<szFactors<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll low=0,high=szvt-1,mid,ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            //cout<<low<<" "<<high<<" "<<mid<<endl;
            if(vt[mid]>=l && vt[mid]<=h)
            {
                ans=mid;
                low=mid+1;
            }
            else if(vt[mid]<l)
            {
                low=mid+1;
            }
            else if(vt[mid]>h)
            {
                high=mid-1;
            }

        }
        if(ans>=szvt || ans<0)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<vt[ans]<<endl;
        }
    }

    return 0;
}
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    vector<ll>factors;
    for(ll i=1; i<=gc; i++) if(a%i==0 && b%i==0) factors.push_back(i);
    //for(vector<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    ll szFactors=factors.size();
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll ans=-1;
        for(vector<ll>::iterator it=factors.begin(); it!=factors.end(); it++)
        {
           if(*it>=l && *it<=h)
           {
               ans=*it;
           }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    vector<ll>factors;
    for(ll i=1; i<=gc; i++) if(a%i==0 && b%i==0) factors.push_back(i);
    //for(vector<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    ll szFactors=factors.size();
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll ans=-1;
        for(vector<ll>::iterator it=factors.begin(); it!=factors.end(); it++)
        {
            if(l>gc)
            {
                break;
            }
            if(*it>=l && *it<=h)
            {
                ans=*it;
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    ll limit=sqrt(min(a,b))+1;
    set<ll>factors;
    for(ll i=1; i<=limit; i++)
    {
        if(a%i==0 && b%i==0)
        {
            factors.insert(i);
            ll x = a /  i;
            ll y = b / i;
            //cout<<i<<" "<<x<<" "<<y<<endl;

            if(a % x == 0 && b % x == 0)
            {
                factors.insert(x);
            }
            if(a % y == 0 && b % y == 0)
            {
                factors.insert(y);
            }
        }
    }
    //for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    vector<ll>vt;
    for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) vt.push_back(*it);
    ll szvt=vt.size();
    //cout<<szFactors<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll low=0,high=szvt-1,mid,ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            //cout<<low<<" "<<high<<" "<<mid<<endl;
            if(vt[mid]>=l && vt[mid]<=h)
            {
                ans=mid;
                low=mid+1;
            }
            else if(vt[mid]<l)
            {
                low=mid+1;
            }
            else if(vt[mid]>h)
            {
                high=mid-1;
            }

        }
        if(ans>=szvt || ans<0)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<vt[ans]<<endl;
        }
    }

    return 0;
}

/*
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    set<ll>factors;
    for(ll i=1; i<=min(gc,100000000LL); i++)
    {
        if(a%i==0 && b%i==0)
        {
            factors.insert(i);
            ll x = a /  i;
            ll y = b / i;
            //cout<<i<<" "<<x<<" "<<y<<endl;

            if(a % x == 0 && b % x == 0)
            {
                factors.insert(x);
            }
            if(a % y == 0 && b % y == 0)
            {
                factors.insert(y);
            }
        }
    }
    //for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    vector<ll>vt;
    for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) vt.push_back(*it);
    ll szvt=vt.size();
    //cout<<szFactors<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll low=0,high=szvt-1,mid,ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            //cout<<low<<" "<<high<<" "<<mid<<endl;
            if(vt[mid]>=l && vt[mid]<=h)
            {
                ans=mid;
                low=mid+1;
            }
            else if(vt[mid]<l)
            {
                low=mid+1;
            }
            else if(vt[mid]>h)
            {
                high=mid-1;
            }

        }
        if(ans>=szvt || ans<0)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<vt[ans]<<endl;
        }
    }

    return 0;
}
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    ll limit=sqrt(min(a,b))+1;
    set<ll>factors;
    for(ll i=1; i<=max(limit,gc); i++)
    {
        if(a%i==0 && b%i==0)
        {
            factors.insert(i);
            ll x = a /  i;
            ll y = b / i;
            //cout<<i<<" "<<x<<" "<<y<<endl;

            if(a % x == 0 && b % x == 0)
            {
                factors.insert(x);
            }
            if(a % y == 0 && b % y == 0)
            {
                factors.insert(y);
            }
        }
    }
    //for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    vector<ll>vt;
    for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) vt.push_back(*it);
    ll szvt=vt.size();
    //cout<<szFactors<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll low=0,high=szvt-1,mid,ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            //cout<<low<<" "<<high<<" "<<mid<<endl;
            if(vt[mid]>=l && vt[mid]<=h)
            {
                ans=mid;
                low=mid+1;
            }
            else if(vt[mid]<l)
            {
                low=mid+1;
            }
            else if(vt[mid]>h)
            {
                high=mid-1;
            }

        }
        if(ans>=szvt || ans<0)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<vt[ans]<<endl;
        }
    }

    return 0;
}

/*
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    set<ll>factors;
    for(ll i=1; i<=min(gc,100000000LL); i++)
    {
        if(a%i==0 && b%i==0)
        {
            factors.insert(i);
            ll x = a /  i;
            ll y = b / i;
            //cout<<i<<" "<<x<<" "<<y<<endl;

            if(a % x == 0 && b % x == 0)
            {
                factors.insert(x);
            }
            if(a % y == 0 && b % y == 0)
            {
                factors.insert(y);
            }
        }
    }
    //for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) cout<<*it<<" ";
    vector<ll>vt;
    for(set<ll>::iterator it=factors.begin(); it!=factors.end(); it++) vt.push_back(*it);
    ll szvt=vt.size();
    //cout<<szFactors<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll l,h,m;
        cin>>l>>h;
        ll low=0,high=szvt-1,mid,ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            //cout<<low<<" "<<high<<" "<<mid<<endl;
            if(vt[mid]>=l && vt[mid]<=h)
            {
                ans=mid;
                low=mid+1;
            }
            else if(vt[mid]<l)
            {
                low=mid+1;
            }
            else if(vt[mid]>h)
            {
                high=mid-1;
            }

        }
        if(ans>=szvt || ans<0)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<vt[ans]<<endl;
        }
    }

    return 0;
}
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool isDivisable(ll a,ll b,ll predictDivisor)
{
    if(a%predictDivisor==0 && b%predictDivisor==0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
ll gcd(ll a,ll b)
{
    if(b==0)
    {
        return a;
    }
    else
    {
        return gcd(b,a%b);
    }
}

int main()
{
    ll a,b;
    cin>>a>>b;
    ll gc=gcd(a,b);
    //cout<<gc<<endl;
    ll n;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        ll low,high,mid;
        cin>>low>>high;
        ll ans=-1;
        while(low<=high)
        {
            mid=(low+high)/2;
            //cout<<low<<" "<<high<<" "<<mid<<" "<<isDivisable(a,b,mid)<<endl;
            if(isDivisable(a,b,mid)==true)
            {
                ans=mid;
                low=mid+1;
            }
            else if(mid>gc)
            {
                high=mid-1;
            }
            else
            {
                low=mid+1;
            }
//            cout<<low<<" "<<high<<" "<<mid<<" "<<isDivisable(a,b,mid)<<endl;
//            cout<<"------------------------------"<<endl;
        }
        cout<<ans<<endl;
    }

    return 0;
}


/** Sourav Kumar
    Department of CSE, HSTU **/

#include<bits/stdc++.h>
using namespace std;
void seealldivisor(long long  n,long long x,long long y)
{
    if(n>=x && n<=y)
        cout << n << endl;
    else
    {
        bool flag = true;
        vector <long long> divisor;
        for(long long  i=1; i*i<=n; i++)
        {
            if(n%i==0)
            {
                if(i*i==n)
                {
                    divisor.push_back(i);
                }
                else
                {
                    divisor.push_back(i);
                    divisor.push_back(n/i);
                }
            }
        }
        sort(divisor.begin(),divisor.end());
        reverse(divisor.begin(),divisor.end());

        for(const auto &it : divisor)
        {
            if(it>=x && it<=y)
            {
                flag = false;
                cout << it << endl;
                break;
            }
        }
        if(flag)
            cout << "-1" << endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    long long  n,a,b,m,q,i,j;
    cin >> a >> b;
    cin >> q;
    long long x = __gcd(a,b);
    for(i=0; i<q; i++)
    {
        cin >> n >> m;
        seealldivisor(x,n,m);
    }
}


/** Sourav Kumar
    Department of CSE, HSTU **/

#include<bits/stdc++.h>
using namespace std;
void seealldivisor(long long  n,long long x,long long y)
{
    if(n>=x && n<=y)
        cout << n << endl;
    else
    {
        bool flag = true;
        vector <long long> divisor;
        for(long long  i=1; i*i<=n; i++)
        {
            if(n%i==0)
            {
                if(i*i==n)
                {
                    divisor.push_back(i);
                }
                else
                {
                    divisor.push_back(i);
                    divisor.push_back(n/i);
                }
            }
        }
        sort(divisor.begin(),divisor.end());

        auto it2 = upper_bound(divisor.begin(),divisor.end(),y);
        int d = distance(divisor.begin(),it2);

        if(divisor[d-1]>=x)
            cout << divisor[d-1] << endl;

        else
            cout << "-1" << endl;

    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    long long  n,a,b,m,q,i,j;
    cin >> a >> b;
    cin >> q;
    long long x = __gcd(a,b);
    for(i=0; i<q; i++)
    {
        cin >> n >> m;
        seealldivisor(x,n,m);
    }
}


/** Sourav Kumar
    Department of CSE, HSTU **/

#include<bits/stdc++.h>
using namespace std;
void seealldivisor(long long  n,long long x,long long y)
{

    bool flag = true;
    vector <long long> divisor;
    for(long long  i=1; i*i<=n; i++)
    {
        if(n%i==0)
        {
            if(i*i==n)
            {
                divisor.push_back(i);
            }
            else
            {
                divisor.push_back(i);
                divisor.push_back(n/i);
            }
        }
    }
    sort(divisor.begin(),divisor.end());
    reverse(divisor.begin(),divisor.end());

    for(const auto &it : divisor)
    {
        if(it>=x && it<=y)
        {
            flag = false;
            cout << it << endl;
            break;
        }
    }
    if(flag)
        cout << "-1" << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long  n,a,b,m,q,i,j;
    cin >> a >> b;
    cin >> q;
    long long x = __gcd(a,b);
    for(i=0; i<q; i++)
    {
        cin >> n >> m;
        seealldivisor(x,n,m);
    }
}


/** Sourav Kumar
    Department of CSE, HSTU **/

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long  a,b,m,q,i,j,x,y;
    cin >> a >> b;
    cin >> q;
    x = __gcd(a,b);
    vector <long long> divisor;

    for(i=1; i*i<=x; i++)
    {
        if(x%i==0)
        {
            if(i*i==x)
            {
                divisor.push_back(i);
            }
            else
            {
                divisor.push_back(i);
                divisor.push_back(x/i);
            }
        }
    }
    sort(divisor.begin(),divisor.end());
    while(q--)
    {
        cin >> x >> y;

        auto it2 = upper_bound(divisor.begin(),divisor.end(),y);
        int d = distance(divisor.begin(),it2);

        if(divisor[d-1]>=x)
            cout << divisor[d-1] << endl;

        else
            cout << "-1" << endl;
    }

}


/** Sourav Kumar
    Department of CSE, HSTU **/

#include<bits/stdc++.h>
using namespace std;
void seealldivisor(long long  n,long long x,long long y)
{

    bool flag = true;
    vector <long long> divisor;
    for(long long  i=1; i*i<=n; i++)
    {
        if(n%i==0)
        {
            if(i*i==n)
            {
                divisor.push_back(i);
            }
            else
            {
                divisor.push_back(i);
                divisor.push_back(n/i);
            }
        }
    }
    int res = -1;
    for(auto it=divisor.begin(); it!=divisor.end(); it++)
    {
        int d = *it;
        if(d>=x && d<=y)
        {
            res = max(res,d);
        }
    }
    cout << res << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long  n,a,b,m,q,i,j;
    cin >> a >> b;
    cin >> q;
    long long x = __gcd(a,b);
    for(i=0; i<q; i++)
    {
        cin >> n >> m;
        seealldivisor(x,n,m);
    }
}


/** Sourav Kumar
    Department of CSE, HSTU **/

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long  a,b,m,q,i,j,x,y;
    cin >> a >> b;
    cin >> q;
    x = __gcd(a,b);
    vector <long long> divisor;

    for(i=1; i*i<=x; i++)
    {
        if(x%i==0)
        {
            if(i*i==x)
            {
                divisor.push_back(i);
            }
            else
            {
                divisor.push_back(i);
                divisor.push_back(x/i);
            }
        }
    }
    while(q--)
    {
        cin >> x >> y;
        int res = -1;
        for(auto it=divisor.begin(); it!=divisor.end(); it++)
        {
            int d = *it;
            if(d>=x && d<=y)
            {
                res = max(res,d);
            }
        }
        cout << res << endl;
    }

}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include<set>
#include<map>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

set<int> ss;
set<int>::iterator it;
int main()
{
	long long n, q, w, e, ans, z, x,a,b;
	ans = 0;
	cin >> q >> w;
	cin >> n;
	ss.insert(1);

	for (int i = 1; i <= sqrt(max(q, w)); i++) {
		if (q%i == 0 || w % i == 0) {
			if (q%i == 0 && w % i == 0)
				ss.insert(i);
			if (q%i == 0 && w % (q / i) == 0)
				ss.insert(w / (q / i));
			if (w%i == 0 && q % (w / i) == 0)
				ss.insert(q / (w / i));
		}
	}
	//ss.insert(max(q, w));
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		it = ss.lower_bound(b);
		if (it != ss.end() && *it <= b) {}
		else
		if (it != ss.begin())
			it--;
		if (*it >= a && it != ss.end()) {
			cout << *it << endl;
		}
		else cout << -1 << endl;
	}
//qw
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include<set>
#include<map>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

set<int> ss;
set<int>::iterator it;
int main()
{
	long long n, q, w, e, ans, z, x,a,b;
	ans = 0;
	cin >> q >> w;
	cin >> n;
	ss.insert(1);

	for (int i = 1; i <= sqrt(max(q,w)); i++) {
		if (q%i == 0 || w % i == 0) {
			if (q%i == 0 && w % i == 0)
			ss.insert(i);
			if (q%i == 0 && w % (q / i) == 0)
				ss.insert(w / (q / i));
			if (w%i == 0 && q % (w / i) == 0)
				ss.insert(q / (w / i));
	}
	//ss.insert(max(q, w));
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		it = ss.lower_bound(b);
		if (it != ss.end() && *it <= b) {}
		else
		if (it != ss.begin())
			it--;
		if (*it >= a && it != ss.end()) {
			cout << *it << endl;
		}
		else cout << -1 << endl;
	}
//qw
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include<set>
#include<map>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

set<int> ss;
set<int>::iterator it;
int main()
{
	long long n, q, w, e, ans, z, x,a,b;
	ans = 0;
	cin >> q >> w;
	cin >> n;
	ss.insert(1);

	for (int i = 1; i <= sqrt(max(q,w)); i++) {
		if (q%i == 0 && w%i == 0)
			ss.insert(i);
		if(max(q,w)% (max(q, w) / i) ==0)
			if (min(q, w)%((max(q, w) / i))==0 )
				ss.insert(max(q, w) / i);
		if (max(q, w) % (min(q, w) / i) == 0)

			if (max(q, w) % ((min(q, w) / i)) == 0)
				ss.insert(min(q, w) / i);

		//asd
	}
	//ss.insert(max(q, w));
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		it = ss.lower_bound(b);
		if (it != ss.end() && *it <= b) {}
		else
		if (it != ss.begin())
			it--;
		if (*it >= a && it != ss.end()) {
			cout << *it << endl;
		}
		else cout << -1 << endl;
	}
//qw
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include<set>
#include<map>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

set<int> ss;
set<int>::iterator it;
int main()
{
	long long n, q, w, e, ans, z, x,a,b;
	ans = 0;
	cin >> q >> w;
	cin >> n;
	ss.insert(1);

	for (int i = 1; i <= sqrt(max(q,w)); i++) {
		if (q%i == 0 && w%i == 0)
			ss.insert(i);
			if (min(q, w)%((max(q, w) / i))==0 )
				ss.insert(max(q, w) / i);
			if (max(q, w) % ((min(q, w) / i)) == 0)
				ss.insert(min(q, w) / i);

		//asd
	}
	//ss.insert(max(q, w));
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		it = ss.lower_bound(b);
		if (it != ss.end() && *it <= b) {}
		else
		if (it != ss.begin())
			it--;
		if (*it >= a && it != ss.end()) {
			cout << *it << endl;
		}
		else cout << -1 << endl;
	}
//qw
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include<set>
#include<map>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

set<int> ss;
set<int>::iterator it;
int main()
{
	long long n, q, w, e, ans, z, x,a,b;
	ans = 0;
	cin >> q >> w;
	cin >> n;
	ss.insert(1);

	for (int i = 1; i <= sqrt(max(q,w)); i++) {
		if (q%i == 0 && w%i == 0) {
			ss.insert(i);
			if (min(q, w)%((max(q, w) / i))==0 )
				ss.insert(max(q, w) / i);
		}
		//asd
	}
	//ss.insert(max(q, w));
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		it = ss.lower_bound(b);
		if (it != ss.end() && *it <= b) {}
		else
		if (it != ss.begin())
			it--;
		if (*it >= a && it != ss.end()) {
			cout << *it << endl;
		}
		else cout << -1 << endl;
	}
//qw
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include<set>
#include<map>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

set<int> ss;
set<int>::iterator it;
int main()
{
	long long n, q, w, e, ans, z, x,a,b;
	ans = 0;
	cin >> q >> w;
	cin >> n;
	ss.insert(1);

	for (int i = 1; i <= sqrt(max(q,w)); i++) {
		if (q%i == 0 && w%i == 0) {
			ss.insert(i);
			if (min(q, w)%((max(q, w) / i))==0 )
				ss.insert(max(q, w) / i);
			if (max(q, w) % ((min(q, w) / i)) == 0)
				ss.insert(min(q, w) / i);
		}
		//asd
	}
	//ss.insert(max(q, w));
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		it = ss.lower_bound(b);
		if (it != ss.end() && *it <= b) {}
		else
		if (it != ss.begin())
			it--;
		if (*it >= a && it != ss.end()) {
			cout << *it << endl;
		}
		else cout << -1 << endl;
	}
//qw
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include<set>
#include<map>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

set<int> ss;
set<int>::iterator it;
int main()
{
	long long n, q, w, e, ans, z, x,a,b;
	ans = 0;
	cin >> q >> w;
	cin >> n;
	ss.insert(1);

	for (int i = 1; i <= sqrt(max(q, w)); i++) {
		if (q%i == 0 || w % i == 0) {
			if (q%i == 0 && w % i == 0)
				ss.insert(i);
			if (q% (q / i) == 0 && w % (q / i) == 0)
				ss.insert(q / i);
			if (w% (w / i) == 0 && q % (w / i) == 0)
				ss.insert(w / i);
		}
	}
	//ss.insert(max(q, w));
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		it = ss.lower_bound(b);
		if (it != ss.end() && *it <= b) {}
		else
		if (it != ss.begin())
			it--;
		if (*it >= a && it != ss.end()) {
			cout << *it << endl;
		}
		else cout << -1 << endl;
	}
//qw
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include<set>
#include<map>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

set<int> ss;
set<int>::iterator it;
int main()
{
	long long n, q, w, e, ans, z, x,a,b;
	ans = 0;
	cin >> q >> w;
	cin >> n;
	ss.insert(1);

	for (int i = 1; i <= sqrt(max(q,w)); i++) {
		if (q%i == 0 && w%i == 0)
			ss.insert(i);
		if(max(q,w)%i==0)
			if (min(q, w)%((max(q, w) / i))==0 )
				ss.insert(max(q, w) / i);
		if (max(q, w) % i == 0)

			if (max(q, w) % ((min(q, w) / i)) == 0)
				ss.insert(min(q, w) / i);

		//asd
	}
	//ss.insert(max(q, w));
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		it = ss.lower_bound(b);
		if (it != ss.end() && *it <= b) {}
		else
		if (it != ss.begin())
			it--;
		if (*it >= a && it != ss.end()) {
			cout << *it << endl;
		}
		else cout << -1 << endl;
	}
//qw
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod
#define ll  long long
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int l, h, q, x, y, ans = -1;
    cin >> l >> h;
    vector<int>v;
    int t = __gcd(l, h);
    for (int i = 1; i <= sqrt(t); i++) {
        if (h % i == 0) {
            v.push_back(i);
            v.push_back(t / i);
        }
    }
    sort(v.begin(),v.end());
    cin >> q;
    while (q--) {
        cin >> x >> y;
        ans = -1;
        for (int i = 0; i < v.size(); i++) {
            if (v[i] >= x && v[i] <= y)
                ans = v[i];
        }
        cout << ans << endl;
    }

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod
#define ll  long long
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int l, h, q, x, y, ans = -1;
    cin >> l >> h;
    vector<int>v;
    int t = __gcd(l, h);
    for (int i = 1; i <= sqrt(t); i++) {
        if (h % i == 0) {
            v.push_back(i);
            v.push_back(t / i);
        }
    }
    cin >> q;
    while (q--) {
        cin >> x >> y;
        ans = -1;
        for (int i = 0; i < v.size(); i++) {
            if (v[i] >= x && v[i] <= y)
                ans = v[i];
        }
        cout << ans << endl;
    }

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod
#define ll  long long
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int l, h, q, x, y, ans = -1;
    scanf("%d%d",&l,&h);
    vector<int>v;
    int t = __gcd(l, h);
    for (int i = 1; i <= t; i++) {
        if (h % i == 0&&l%i==0)
            v.push_back(i);
    }
    scanf("%d",&q);
    while (q--) {
        scanf("%d%d",&x,&y);
        ans = -1;
        vector<int>::iterator u;
        u=upper_bound(v.begin(), v.end(), y);
        if(v[u- v.begin()]>y ||v[u-v.begin()-1]<x)
        {
            printf("-1\n");
        }
        else
        {
            printf("%d\n",v[u- v.begin()-1]);
        }
    }

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod
#define ll  long long
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int l, h, q, x, y, ans = -1;
    cin >> l >> h;
    vector<int>v;
    int t = __gcd(l, h);
    for (int i = 1; i <= sqrt(t); i++) {
        if (l % i == 0) {
            v.push_back(i);
            v.push_back(t / i);
        }
    }
    sort(v.begin(),v.end());
    cin >> q;
    while (q--) {
        cin >> x >> y;
        ans = -1;
        for (int i = 0; i < v.size(); i++) {
            if (v[i] >= x && v[i] <= y)
                ans = v[i];
        }
        cout << ans << endl;
    }

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod
#define ll  long long
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int l, h, q, x, y, ans = -1;
    cin >> l >> h;
    vector<int>v;
    int t = __gcd(l, h);
    for (int i = 1; i <= sqrt(t); i++) {
        if (t % i == 0) {
            v.push_back(i);
            v.push_back(t / i);
        }
    }
    sort(v.begin(),v.end());
    cin >> q;
    while (q--) {
        cin >> x >> y;
        ans = -1;
        for (int i = 0; i < v.size(); i++) {
            if (v[i] >= x && v[i] <= y)
                ans = v[i];
        }
        cout << ans << endl;
    }

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod
#define ll  long long
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int l, h, q, x, y, ans = -1;
    cin >> l >> h;
    vector<int>v;
    int t = __gcd(l, h);
    for (int i = 1; i <= t; i++) {
        if (h % i == 0&&l%i==0)
            v.push_back(i);
    }
    cin >> q;
    while (q--) {
        cin >> x >> y;
        ans = -1;
        for (int i = 0; i < v.size(); i++) {
            if (v[i] >= x && v[i] <= y)
                ans = v[i];
        }
        cout << ans << endl;
    }

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod
#define ll  long long
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int l, h, q, x, y, ans = -1;
    scanf("%d%d",&l,&h);
    vector<int>v;
    int t = __gcd(l, h);
    for (int i = 1; i <= t; i++) {
        if (h % i == 0&&l%i==0)
            v.push_back(i);
    }
    scanf("%d",&q);
    while (q--) {
        scanf("%d%d",&x,&y);
        ans = -1;
        vector<int>::iterator u;
        u=upper_bound(v.begin(), v.end(), y);
        if(v[u-v.begin()-1]<x)
        {
            printf("-1\n");
        }
        else
        {
            printf("%d\n",v[u- v.begin()-1]);
        }
    }

    return 0;
}


#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int,ll int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}
//string add(string s,int n){ string res; int c=n,x; for(int i=s.size()-1;i>=0;i--)   { x=s[i]-'0'+c;res+=(x%10+'0'); c=x/10; }    while(c)    { res+=(c%10+'0'); c=c/10;} reverse(res.begin(),res.end()); return res;}

int main()
{
    //FAST();
    ll int n,m,x,a,b,gcd;
    cin>>n>>m;
    gcd=__gcd(n,m);
    ll int sq=sqrt(gcd);
    cin>>x;
    while(x--)
    {
        cin>>a>>b;
        ll int res=-1;
        for(ll int i=max(1,a);i<=min(b,sq);i++)
        {
            if(gcd%i==0)
            {
                if(i>=a&&i<=b)
                {
                    res=max(res,i);
                }
                if(gcd/i>=a&&gcd/i<=b)
                {
                    res=max(res,gcd/i);
                    break;
                }
            }
        }
        cout<<res<<endl;

    }

}


#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int,ll int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}
//string add(string s,int n){ string res; int c=n,x; for(int i=s.size()-1;i>=0;i--)   { x=s[i]-'0'+c;res+=(x%10+'0'); c=x/10; }    while(c)    { res+=(c%10+'0'); c=c/10;} reverse(res.begin(),res.end()); return res;}

int main()
{
    //FAST();
    ll int n,m,x,a,b,gcd;
    cin>>n>>m;
    gcd=__gcd(n,m);
    ll int sq=sqrt(gcd);
    cin>>x;
    while(x--)
    {
        cin>>a>>b;
        ll int res=-1;
        for(ll int i=max(1LL,a);i<=min(b,sq);i++)
        {
            if(gcd%i==0)
            {
                if(i>=a&&i<=b)
                {
                    res=max(res,i);
                }
                if(gcd/i>=a&&gcd/i<=b)
                {
                    res=max(res,gcd/i);
                    break;
                }
            }
        }
        cout<<res<<endl;

    }

}


#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int,ll int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}
//string add(string s,int n){ string res; int c=n,x; for(int i=s.size()-1;i>=0;i--)   { x=s[i]-'0'+c;res+=(x%10+'0'); c=x/10; }    while(c)    { res+=(c%10+'0'); c=c/10;} reverse(res.begin(),res.end()); return res;}

int main()
{
    //FAST();
    ll int n,m,x,a,b,gcd;
    cin>>n>>m;
    gcd=__gcd(n,m);
    ll int sq=sqrt(gcd);
    vector<ll int>v;
    for(int i=1;i<=sq;i++)
    {
        if(gcd%i==0){v.pb(i);
        if(gcd/i!=i)v.pb(gcd/i);
        }
    }
   _sort(v);

    cin>>x;
    while(x--)
    {
        cin>>a>>b;
        ll int res=-1;
       for(int i=v.size()-1;i>=0;i--)
       {
           if(v[i]>=a&&v[i]<=b)
           {
               res=v[i];
               break;
           }
       }
        cout<<res<<endl;

    }

}


#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int,ll int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}
//string add(string s,int n){ string res; int c=n,x; for(int i=s.size()-1;i>=0;i--)   { x=s[i]-'0'+c;res+=(x%10+'0'); c=x/10; }    while(c)    { res+=(c%10+'0'); c=c/10;} reverse(res.begin(),res.end()); return res;}

int main()
{
    //FAST();
    ll int n,m,x,a,b,gcd;
    cin>>n>>m;
    gcd=__gcd(n,m);
    ll int sq=sqrt(gcd);
    cin>>x;
    while(x--)
    {
        cin>>a>>b;
        ll int res=-1;
        for(ll int i=1;i<=min(b,sq);i++)
        {
            if(gcd%i==0)
            {
                if(i>=a&&i<=b)
                {
                    res=max(res,i);
                }
                if(gcd/i>=a&&gcd/i<=b)
                {
                    res=max(res,gcd/i);
                    break;
                }
            }
        }
        cout<<res<<endl;

    }

}


#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int,ll int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}
//string add(string s,int n){ string res; int c=n,x; for(int i=s.size()-1;i>=0;i--)   { x=s[i]-'0'+c;res+=(x%10+'0'); c=x/10; }    while(c)    { res+=(c%10+'0'); c=c/10;} reverse(res.begin(),res.end()); return res;}

int main()
{
    //FAST();
    ll int n,m,x,a,b,gcd;
    cin>>n>>m;
    gcd=__gcd(n,m);
    ll int sq=sqrt(gcd);
    cin>>x;
    while(x--)
    {
        cin>>a>>b;
        ll int res=-1;
        for(ll int i=1;i<=sq;i++)
        {
            if(gcd%i==0)
            {
                if(i>=a&&i<=b)
                {
                    res=max(res,i);
                }
                if(gcd/i>=a&&gcd/i<=b)
                {
                    res=max(res,gcd/i);
                }
            }
        }
        cout<<res<<endl;

    }

}