############################################################# import sys sys.setrecursionlimit(10**7) from heapq import heappop,heappush from collections import deque,defaultdict,Counter from bisect import bisect_left, bisect_right from itertools import product,combinations,permutations ipt = sys.stdin.readline def iin(): return int(ipt()) def lmin(): return list(map(int,ipt().split())) MOD = 998244353 ############################################################# def solve(N,K): L = len(N) cnt = 0 for i in range(1,L): for j in range(i): if j >= len(K): break cnt += (int(K[j])-(j==0))*10**(i-j-1) #print(j,cnt,int(K[j])-(j==0)) if i < len(K): cnt += 1 #print("a") #print(cnt) f = 0 for j in range(L): if j >= len(K): break if f == 0: if int(N[j]) > int(K[j]): cnt += (int(K[j])-(j==0))*10**(L-j-1) f = 1 elif int(N[j]) < int(K[j]): cnt += (int(N[j])-(j==0))*10**(L-j-1) #f = 2 cnt += int(N)-int(N[:j+1])*10**(L-j-1)+1 break else: cnt += (int(K[j])-(j==0))*10**(L-j-1) elif f == 1: cnt += int(K[j])*10**(L-j-1) cnt += 1 return cnt for _ in range(iin()): N,K = input().split() print(solve(N,K))