#include<bits/stdc++.h>
using namespace std;
#define mo 1000000007ll
#define N 110
#define int long long
struct no{
	int x,y;
};
vector<no>v[N];
int f[N],q;
signed main(){
	v[1].push_back((no){1,2});
	v[1].push_back((no){1,3});
	v[1].push_back((no){1,4});
	f[0]=f[1]=1;
	for(int i=2;i<=100;i++)
		f[i]=f[i-1]+f[i-2];
	for(int i=1;i<=97;i++)
		for(auto x:v[i]){
			int a=x.y,b=x.x+a;
			while(b<=f[i+3]+f[i])
				v[i+1].push_back((no){a,b}),b+=a;
		}
	cin>>q;
	while(q--){
		int n,m;
		cin>>n>>m;
		if(n>m)swap(n,m);
		int g=1,r=0;
		while(f[g+1]<=n&&f[g+2]<=m)g++;
		cout<<g<<' ';
		if(g==1)cout<<n%mo*m%mo<<'\n';
		else{
			for(auto x:v[g-1]){
			int a=x.x,b=x.y;
			if(b<=n)r=(r+(m-a)/b)%mo;
			if(b<=m)r=(r+(n-a)/b)%mo;
		}
		cout<<r<<'\n';
		}
	}
}