// #include <iostream>
// #include<vector>
// #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
 
const int M = 1'000'000'007;
const int INF=1e9+5;
// const long long INF = LLONG_MAX / 4;

// void addi(int& a,int b){
//     a+=b;
//     while (a>=M){
//         a-=M;
//     }
// }

    // if say till i its a boring number so if ith pos is odd and i put odd
    // at it (even case also) so i will pass on the boringness to i+1 otherwise
    // i wont pass boringness further

int cnt(bool flag,int i,string rs){
        long long x;
        int n=rs.size();
        if (flag){
            string xs;
            if (0 <= n-i+1 && n-i+1 < n){
                xs=rs.substr(n-i+1);
            } 
            else {
                xs="0";
            }
            x = stoi(xs)+1;
            }

        else{
            x = (pow(10, i-1)+0.1);

        }
        return x;
        }
int f(long long r){
    string rs = to_string(r);
    int n=rs.size();
    vector<vector<long long> >dp(n+1,vector<long long>(2,0));

    for(int i=1;i<=n;i++){
        for(int tight=0;tight<2;tight++){
            int ub = tight? (rs[n-i]-'0'):9;
            
            
            for(int d=0;d<=ub;d++){
                dp[i][tight]+=(d*cnt(tight & (d==ub),i,rs)+dp[i-1][tight & (d==ub)]);
            }
                
}
   }
    return dp[n][1];
}
  
    


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t;
    cin>>t;
    
    while(t>0){
        long long x,y;
        cin>> x>>y;
        
        long long ans= f(y)-f(x-1);

        cout<< ans<<endl;
        t--;

    }
    return 0;
}
