#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100005;
int q;
long long l,r;
int rs[12]={0,1,3,6,1,6,3,1,0,0};
int main()
{
freopen("xiaokai.in","r",stdin);
freopen("xiaokai.out","w",stdout);
scanf("%d",&q);
for(int i=1;i<=q;++i)
{
scanf("%lld%lld",&l,&r);
--l;
l%=9;
r%=9;
printf("%d\n",(rs[r]-rs[l]+9)%9);
}
return 0;
}