#include<bits/stdc++.h>
using namespace std;
int Q;
unsigned long long l,r;
int modx=9;
int main()
{
freopen("xiaokai.in","r",stdin);
freopen("xiaokai.out","w",stdout);
scanf("%d",&Q);
for(int i=1;i<=Q;++i)
{
unsigned long long ans=0;
scanf("%llu%llu",&l,&r);
unsigned long long cnt=r-l+1;
unsigned long long cnt1,cnt2;
cnt1=cnt/9;
for(unsigned long long j=l;j<=min(l+8,r);++j)
{
ans=(ans+j%modx)%modx;
}
ans=(ans*cnt1)%modx;
for(unsigned long long j=l+9*cnt1;j<=r;++j)
{
ans=(ans+j%modx)%modx;
}
printf("%llu \n",ans);
}
return 0;
}