#include <iostream>
#include <fstream>
#include <string>
using namespace std;
using ull = unsigned long long;
int main(void) {
ifstream fin("xiaokai.in");
ofstream fout("xiaokai.out");
int Q;
fin >> Q;
ull l, r;
ull sum;
for(int k = 0; k < Q; ++k) {
fin >> l >> r;
sum = 0;
for(ull i = l; i % 9 != 0; ++i)
sum += i;
for(ull i = r; i % 9 != 0; --i)
sum += i;
fout << sum % 9 << endl;
}
return 0;
}