#include <bits/stdc++.h>
using namespace std;
#define ll int
#define nhanh ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define nmax 1000007
#define fi first
#define se second
#define pll pair<ll,ll>
const ll mod = 1e9+7;
ll n,k,x,y,z,dp[10],cnt[10],ans = 0;
void lis(ll x)
{

    vector<ll> vt;
    while (x > 0)
    {
        vt.push_back(x % 10);
        x/=10;
    }
    reverse(vt.begin(),vt.end());

    memset(dp,0x3f,sizeof(dp));

    for (int i = 0; i < vt.size(); i++)
    {
        ll p = lower_bound(vt.begin(),vt.end(), vt[i]) - vt.begin();
        if (p == vt.size()) continue;
        dp[p] = vt[i];

        ans = max(ans, p + 1);
        cnt[p + 1]++;
    }


}
void sol(ll x,ll y)
{
    for (int i = x; i <= y; i++)
    {
           lis(i);
    }
    cout <<ans <<" "<<cnt[ans]<<"\n";
    memset(cnt,0,sizeof(cnt));
    ans = 0;

}
int main()
{
    freopen("LISX.INP","r",stdin);
    freopen("LISX.OUT","w",stdout);
    nhanh
    cin >> n;
    while (n--)
    {
        cin >> x >> y;
        sol(x, y);
    }
}
