#include<bits/stdc++.h>
using namespace std;
const long long inf=1e18;
const long long Mod=1000000007;
struct node
{
	long long x,y;
};
int q;
long long fib[100];
vector<node> v[100],ch;
int main()
{
	fib[0]=fib[1]=1;
	int k=1;
	while (true)
	{
		k++;
		fib[k]=fib[k-1]+fib[k-2];
		if (fib[k]>inf)
		{
			break;
		}
	}
	k--;
	v[1].push_back((node){1,2});
	v[1].push_back((node){1,3});
	v[1].push_back((node){1,4});
	for (int i=1;i<k-2;i++)
	{
		for (int j=0;j<v[i].size();j++)
		{
			long long x=v[i][j].x;
			long long y=v[i][j].y;
			x+=y;
			while (x<=fib[i]+fib[i+3])
			{
				v[i+1].push_back((node){y,x});
				x+=y;
			}
		}
	}
	scanf("%d",&q);
	while (q--)
	{
		long long n,m;
		scanf("%lld%lld",&n,&m);
		if (n>m)
		{
			swap(n,m);
		}
		k=1;
		while (fib[k+1]<=n && fib[k+2]<=m)
		{
			k++;
		}
		printf("%d ",k);
		if (k==1)
		{
			n%=Mod;
			m%=Mod;
			printf("%lld\n",n*m%Mod);
			continue;
		}
		long long ans=0;
		k--;
		for (int i=0;i<v[k].size();i++)
		{
			long long x=v[k][i].x;
			long long y=v[k][i].y;
			if (y<=n)
			{
				ans=(ans+(m-x)/y)%Mod;
			}
			if (y<=m)
			{
				ans=(ans+(n-x)/y)%Mod;
			}
		}
		printf("%lld\n",ans);
	}
    return 0;
}
//凝眸顾盼柔情藏，灵动佳人婉清扬。