//=======================^========================================================^=======================\\
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
*/
//=======================^========================================================^=======================\\
#include<iostream>
#include<math.h>
#include<stdlib.h>
// #include<bits/stdc++.h>
#include<string.h>
#include<ctype.h>
#include<set>
#include<vector>
#include <algorithm>
#include<map>
#define test ll t;cin>>t;while(t--)
#define ll long long int
#define lld long double
#define f first
#define s second
#define inarr ll n;cin>>n;ll arr[n+1];fi(0,n) cin>>arr[i]
#define setfor for(auto it: s1)
#define parthparekh ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi(l,r) for(ll i = l; i < r; i++)
#define fj(l,r) for(ll j = l; j < r; j++)
#define fk(l,r) for(ll k = l; k < r; k++)
#define fir(r,l) for(ll i=r;i>=l;i--)
#define fjr(r,l) for(ll j=r;j>=l;j--)
const ll MOD=1e9+7;
const ll MOD2= 998244353;
const ll inf=1e18;
const ll N=1e6+100;
#define pb push_back
#define em emplace_back
#define yy cout<<"YES\n"
#define nn cout<<"NO\n"
using namespace std;
int main()
{
parthparekh;
ll t;
cin>>t;
while(t--){
ll ans=0,ans1=0;
string s1,s2;
cin>>s1>>s2;
if(s1==s2)
cout<<0<<endl;
else{
if(s1.length()==s2.length()){
fi(0,s1.length()){
if(s2[i]==s1[i])
ans1++;
else
break;
}
ans=((s1.length()-ans1-1)*9)+(s2[ans1]-s1[ans1]);
cout<<ans<<endl;
}
else{
cout<<(s2[0]-48)+(s2.length()-1)*9<<endl;
}
}
}
}
550C - Divisibility by Eight | 5A - Chat Servers Outgoing Traffic |
615A - Bulbs | 5B - Center Alignment |
549A - Face Detection | 535B - Tavas and SaDDas |
722C - Destroying Array | 366A - Dima and Guards |
716B - Complete the Word | 1461C - Random Events |
1627A - Not Shading | 141B - Hopscotch |
47B - Coins | 1466C - Canine poetry |
74A - Room Leader | 1333D - Challenges in school №41 |
1475B - New Year's Number | 461A - Appleman and Toastman |
320B - Ping-Pong (Easy Version) | 948A - Protect Sheep |
387A - George and Sleep | 53A - Autocomplete |
1729G - Cut Substrings | 805B - 3-palindrome |
805C - Find Amir | 676C - Vasya and String |
1042B - Vitamins | 1729F - Kirei and the Linear Function |
25D - Roads not only in Berland | 1694A - Creep |