/*
:::给定 L<=R 求最大的 |ai-bi|+....
100位 一定是贪心 否则数组 炸裂
观察 样例就可以发现 构造答案
1.n!=m 补成m 前缀照抄 string/char -> reverse
string->push_back()
2.首位不变 |A0000000-B9999999| 即可
*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string.h>
//#include<queue>
//#include<vector>
//#include<bits/stdc++.h>
#define ll long long
#define ddd printf("-----------------------\n");
using namespace std;
const int maxn=1e3 +10;
const int mod=998244353;
const int inf=0x3f3f3f3f;
char l[maxn],r[maxn];
int main()
{
ios::sync_with_stdio(false);
int T;cin>>T;
while(T--)
{
cin>>l>>r;
int n=strlen(l),m=strlen(r);
reverse(l,l+n),reverse(r,r+m);
for(int i=n;i<m;i++) l[n++]='0';
while(n&&l[n-1]==r[n-1]) n--;
if(n==0) cout<<"0\n";
else cout<<(n-1)*9+(int)(r[n-1]-l[n-1])<<'\n';
}
return 0;
}