#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=90;
const int mod=1000000007;
ll f[maxn];
typedef pair<ll,ll> pr;
vector<pr> lv[maxn];
int F(ll a,ll b){
  if(a<b)swap(a,b);
  if(a%b==0)return 1;
  return F(b,a%b)+1;
}
void init(){
  f[0]=1;f[1]=1;
  int tot=1;
  while(f[tot]<=1e18){
    ++tot;f[tot]=f[tot-1]+f[tot-2];
  }
  lv[1].push_back(pr(1,2));lv[1].push_back(pr(1,3));
  ll a,b;
  for(int i=2;i<=tot;++i){
    for(vector<pr>::iterator pt=lv[i-1].begin();pt!=lv[i-1].end();++pt){
      a=pt->first;b=pt->second;
      for(int j=1;j<=2;++j){
	if(b*j+a>f[i+2])break;
	if(F(b,b*j+a)==i){
	  lv[i].push_back(pr(b,b*j+a));
	}
      }
    }
    sort(lv[i].begin(),lv[i].end());
    int N=lv[i].size();
    int cnt=0;
    for(int j=0;j<N;++j){
      if(j==0||lv[i][j]!=lv[i][j-1]){
	lv[i][cnt++]=lv[i][j];
      }
    }//printf("%d\n",cnt);
    lv[i].resize(cnt);
  }
  //  printf("%d %lld\n",tot,f[tot]);
}
void work(ll a,ll b){
  if(a==1||b==1){
    if(a==1){
      printf("%d %d\n",1,b%mod);
    }else{
      printf("%d %d\n",1,a%mod);
    }
    return;
  }
  if(a>b)swap(a,b);
  int t=0;
  while(f[t]<=a&&f[t+1]<=b)++t;
  printf("%d ",t-1);
  if(t-1==1)printf("%d\n",a%mod*1ll*(b%mod)%mod);
  else{
    int ans=0;//printf("%d\n",t-2);
    for(vector<pr>::iterator pt=lv[t-2].begin();pt!=lv[t-2].end();++pt){
      ll x=pt->first,y=pt->second;//printf("%d %d\n",x,y);
      if(x>a||x>b)continue;
      if(y<=a)ans=(ans+(b-x)/y)%mod;
      if(y<=b)ans=(ans+(a-x)/y)%mod;
    }
    printf("%d\n",ans);
  }
}
int main(){
  init();int q;scanf("%d",&q);
  ll a,b;
  while(q--){
    scanf("%lld%lld",&a,&b);
    work(a,b);
  }
  return 0;
}
