#include<bits/stdc++.h>
using namespace std;
long long fib[233],x,y,ans;
int now;long long all;
void dfs(long long u,long long v,int c,int err)
{
	//cout<<u<<' '<<v<<' '<<c<<' '<<err<<' '<<(((u>=fib[c+2])&&(v>=fib[c+3]))||(u>x)||(v>y))<<endl;
	if (((u>=fib[c+2])&&(v>=fib[c+3]))||(u>x)||(v>y)) return;
	//if (c==now) {ans+=(int)((u<=x)&&(v<=y))+(int)((v<=x)&&(u<=y));return;}
	if (c==now-1)
	{
		ans+=max(0ll,(y-u)/v)*(v<=x)+max(0ll,(x-u)/v)*(v<=y);
		return;
	}
	if (!err)
	{
		dfs(v,u+v,c+1,0);
		dfs(v,u+v+v,c+1,1);
		//v,u+kv
		//p=fib[now-c-2]*v+fib[now-c-1]*(u+kv)
		//q=fib[now-c-1]*v+fib[now-c]*(u+kv)
		//p<=x q<=y
	}
	else if (err==1)
	{
		if ((double)u*fib[now-2-c]+(double)v*fib[now-1-c]>1.1e18) return;
		if ((double)u*fib[now-1-c]+(double)v*fib[now-0-c]>1.1e18) return;
		long long uu=u*fib[now-2-c]+v*fib[now-1-c],vv=u*fib[now-1-c]+v*fib[now-0-c];
		ans+=max(0ll,(y-uu)/vv)*(vv<=x)+max(0ll,(x-uu)/vv)*(vv<=y);
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	fib[0]=0;fib[1]=1;for (int i=2;i<=90;i++) fib[i]=fib[i-1]+fib[i-2];
	int q;scanf("%d",&q);
	while (q--)
	{//if (q%1000==0) cerr<<q<<endl;
		scanf("%lld%lld",&x,&y);if (x>y) swap(x,y);
		if (x==1) {printf("1 %lld\n",y%1000000007);continue;}
		if (y==2) {printf("1 4\n");continue;}
		now=0;while ((fib[now+2]<=x)&&(fib[now+3]<=y)) now++;
		printf("%d ",now);
		ans=0;dfs(1,1,0,0);
		printf("%lld\n",ans%1000000007);
	}
	cerr<<all<<endl;
}