#include <bits/stdc++.h>
using namespace std;
const int N = 100;
const int MOD = 1e9 + 7;
#define LL long long
#define pI pair <LL, LL>
#define fr first
#define sc second
#define mp make_pair
LL f[N]; int tot;
vector <pI> S[N];
int q;

void print(vector <pI> a)
{
    for (int i = 0; i < a.size(); ++ i)
        cerr << a[i].fr << " " << a[i].sc << endl;
}
int main()
{
    f[0] = f[1] = 1; tot = 1;
    while (f[tot] + f[tot - 1] <= 5e18)
    {
        tot ++;
        f[tot] = f[tot - 1] + f[tot - 2];
    }
    S[1].push_back(mp(1, 2));
    S[1].push_back(mp(1, 3));
    S[1].push_back(mp(1, 4));
    for (int i = 2; i <= tot - 3; ++ i)
        for (int j = 0; j < S[i - 1].size(); ++ j)
            for (int k = 1; k * S[i - 1][j].sc + S[i - 1][j].fr <= f[i + 2]; ++ k)
                S[i].push_back(mp(S[i - 1][j].sc, k * S[i - 1][j].sc + S[i - 1][j].fr));
    scanf("%d", &q);
    while (q --)
    {
        LL x, y, ans = 0;
        scanf("%lld%lld", &x, &y);
        if (x > y) swap(x, y);
        int k = 1;
        while (f[k + 1] <= x && f[k + 2] <= y) k ++;
        for (int i = 0; i < S[k - 1].size(); ++ i)
            if (S[k - 1][i].sc <= x)
                ans += (y - S[k - 1][i].fr) / S[k - 1][i].sc;

        for (int i = 0; i < S[k - 1].size(); ++ i)
            if (S[k - 1][i].sc <= y)
                ans += (x - S[k - 1][i].fr) / S[k - 1][i].sc;
        if (x == 1) ans = y;
        if (x == 2 && y == 2) ans = 4;
        printf("%d %d\n", k, (int)(ans % MOD));
    }
}
