for _ in range(int(input())):
ans = 0
n, m = input().split()
for i in range(int(n), int(m)+1):
ans += str(i).count('0')
print(ans)
for _ in range(int(input())):
ans = 0
n, m = input().split()
for i in range(int(n), int(m)+1):
ans += str(i).count('0')
print(ans)