#include<bits/stdc++.h>
using namespace std;
#define int long long
// JANGAN LUPA CEK PERLU LL NGGAK
#define pb push_back
#define miku ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mo(int x){
if(x%9) return x%9;
else return 9;
}
signed main(){
miku
int q;cin>>q;
while(q--){
int l,r;cin>>l>>r;
int ans=0;
int cur=0;
for(int i=l;;i++){
if(i>r) break;
ans+=mo(i);
cur=i;
if(mo(i)==9) break;
}
cur++;
int sz=(r-cur+1)/9;
ans+=sz*45;
if(sz) cur+=(sz*9)-1;
if(sz) cur++;
for(int i=cur;i<=r;i++){
ans+=mo(i);
}
cout<<ans<<endl;
}
}
// very mathy
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |