http://www.lydsy.com/JudgeOnline/problem.php?id=3834
我只是很好奇我是怎么骗到rank 3的?????
//#define _TEST _TEST
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
/************************************************
Code By willinglive Blog:http://willinglive.cf
************************************************/
#define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++)
#define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--)
#define MS(arr,x) memset(arr,x,sizeof(arr))
#define LL long long
#define INE(i,u,e) for(int i=head[u];~i;i=e[i].next)
inline const int read()
{int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;
for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}
/
/
/
void input()
{
}
void solve()
{
int a,b,c,d;
rep(i,1,read())
{
a=read(); b=read(); c=read(); d=read();
int l=max(a,c);
int r=min(b,d);
if(l<=r) printf("%d\n",r);
else
{
a--;c--;
int mi=min(b,d),r,ans=1;
for(int i=1;i<=mi;i=r+1)
{
r=min(b/(b/i),d/(d/i));
if(a/r<b/r && c/r<d/r) ans=r;
}
printf("%d\n",ans);
}
}
}
/
int main()
{
#ifndef _TEST
freopen("std.in","r",stdin); freopen("std.out","w",stdout);
#endif
input(),solve();
return 0;
}