def solve(N, K): SN = str(N) NN = len(SN) SK = str(K) NK = len(SK) cnt = 0 for i in range(1, int(SK[0])): for j in range(NN): start = i * 10 ** j if start > N: break tmp = start + 10 ** j - 1 if tmp < N: end = tmp cnt += end - start + 1 else: end = N cnt += end - start + 1 break for i in range(NK): start = int(SK[0]) * 10 ** i tmp = int(SK[:i + 1]) if tmp < K: end = tmp cnt += end - start + 1 else: end = K cnt += end - start + 1 break return cnt T = int(input()) for t in range(T): N, K = map(int, input().split()) print(solve(N, K))