#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);
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgaW50CiNkZWZpbmUgbmhhbmggaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTtjaW4udGllKE5VTEwpO2NvdXQudGllKE5VTEwpOwojZGVmaW5lIG5tYXggMTAwMDAwNwojZGVmaW5lIGZpIGZpcnN0CiNkZWZpbmUgc2Ugc2Vjb25kCiNkZWZpbmUgcGxsIHBhaXI8bGwsbGw+CmNvbnN0IGxsIG1vZCA9IDFlOSs3OwpsbCBuLGsseCx5LHosZHBbMTBdLGNudFsxMF0sYW5zID0gMDsKdm9pZCBsaXMobGwgeCkKewoKICAgIHZlY3RvcjxsbD4gdnQ7CiAgICB3aGlsZSAoeCA+IDApCiAgICB7CiAgICAgICAgdnQucHVzaF9iYWNrKHggJSAxMCk7CiAgICAgICAgeC89MTA7CiAgICB9CiAg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