// 河南省实验中学 高中 21级 关天泽
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define re register
#define int ll
const int N = 0x3f3f3f;
using namespace std;
inline int read(){
int ans=0,sgn=1;
char ch=getchar();
while(!isdigit(ch)){
if (ch=='-')sgn=-1;
ch=getchar();
}
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans*sgn;
}
int a, b, m, q;
signed main(){
freopen("xiaokai.in", "r", stdin);
freopen("xiaokai.out", "w", stdout);
q = read();
while (q--){
m = 0;
a = read();
b = read();
b %= 9;
a %= 9;
if (b < a) b += 9;
for (int i = a; i <= b; i++) m += i;
m %= 9;
printf("%d\n", m);
}
return 0;
}