// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MOD = 1e9 + 7;

LL X, Y;
vector<pair<LL, LL>> fib;

inline pair<LL, LL> operator+ (const pair<LL, LL> &a, const pair<LL, LL> &b)
{
    return MP(a.x + b.x, a.y + b.y);
}

void prework()
{
    fib.push_back(MP(1, 0));
    fib.push_back(MP(0, 1));
    while (fib.back().y <= 1e18) {
        fib.push_back(MP(fib[SZ(fib)-2].x + fib.back().x, fib[SZ(fib)-2].y + fib.back().y));
    }
}

int ans, cnt;

void calc(LL x, LL y, int len)
{
    if (x > X || y > Y)
        return;
    if (len == ans) {
        (cnt += ((Y - y) / x + 1) % MOD) %= MOD;
        return;
    }
    int d = ans - len;
    for (int i = 0; i < 2; ++i) {
        LL t1 = x * fib[d].x + y * fib[d].y;
        LL t2 = x * fib[d+1].x + y * fib[d+1].y;
        if (t1 > X || t2 > Y)
            break;
        calc(y, x + y, len + 1);
        y += x;
    }
}

void solve()
{
    if (X > Y)
        std::swap(X, Y);

    for (int i = 0; fib[i].x + fib[i].y <= X; ++i) {
        if (fib[i+1].x + fib[i+1].y <= Y)
            ans = i;
    }
    if (ans <= 1) {
        printf("1 %lld\n", X * Y % MOD);
        return;
    }

    cnt = 0;
    calc(1, 2, 1);
    std::swap(X, Y);
    calc(1, 2, 1);

    printf("%d %d\n", ans, cnt);
}

int main()
{
#ifdef __DEBUG
    freopen("F.in", "r", stdin);
    freopen("F.out", "w", stdout);
#endif

    prework();
    int Q;
    read(Q);
    while (Q--) {
        read(X); read(Y);
        solve();
    }

    return 0;
}

// 彻头彻尾的反Unix系统，就是让进程的生成代价高昂，让进程的控制
// 困难而死板，让IPC可有可无，对它不予支持或支持很少。
//     -- 《UNIX编程艺术》by ESR

Measured memory_bytes: 3968