#include <bits/stdc++.h>
using i64 = long long;
int main() {
freopen("xiaokai.in", "r", stdin);
freopen("xiaokai.out", "w", stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
for (int i = 1; i <= n; ++ i) {
i64 l, r, k, res = 0;
std::cin >> l >> r;
k = (r - l + 1) % 9, r = k + l - 1;
for (i64 i = l; i <= r; ++ i) {
i64 bak = i;
while (bak)
res += bak % 10, bak /= 10;
}
std::cout << res % 9 << '\n';
}
return 0;
}