#include<cstdio>
#include<algorithm>
#include<vector>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
const int mx=90+10,mo=1000000007;
const ll inf=1000000000000000000;
ll fib[mx];
vector<pi> a[mx];
vector<pi>::iterator it;
ll x,y,n,m,num;
int i,j,k,l,t,tot,ca,ans;
int main(){
    fib[0]=fib[1]=1;
    tot=1;
    while (1){
        fib[tot+1]=fib[tot]+fib[tot-1];
        if (fib[tot+1]>inf) break;
        tot++;
    }
    a[1].pb(mp(1,2));a[1].pb(mp(1,3));a[1].pb(mp(1,4));
    fo(i,1,tot-3){
        it=a[i].begin();
        while (it!=a[i].end()){
            x=(*it).xx;y=(*it).yy;
            x+=y;
            while (x<=fib[i+3]){
                a[i+1].pb(mp(y,x));
                x+=y;
            }
            it++;
        }
    }
    scanf("%d",&ca);
    while (ca--){
        scanf("%lld%lld",&n,&m);
        if (n>m) swap(n,m);
        ans=1;
        while (fib[ans+1]<=n&&fib[ans+2]<=m) ans++;
        printf("%d ",ans);
        if (ans==1){
            printf("%lld\n",n*m%mo);
            continue;
        }
        else{
            num=0;
            it=a[ans-1].begin();
            while (it!=a[ans-1].end()){
                x=(*it).xx;y=(*it).yy;
                if (y<=n) (num+=(m-x)/y)%=mo;
                if (y<=m) (num+=(n-x)/y)%=mo;
                it++;
            }
            printf("%d\n",num);
        }
    }
}