You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.

For example:

if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;

if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;

if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.

Changed digits always form a suffix of the result written in the decimal system.

Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.

Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).


-----Output-----

For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.


-----Examples-----

Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110


-----Note-----

None

Source: codeforces | Difficulty: MEDIUM
Tags: Number theory

Sorting

Dynamic programming

Mathematics


Solutions:
def noc(x, y, d):
	n = y - x + 1
	n += x % d
	if (y + 1) % d != 0:
		n += d - (y + 1) % d
	return int(n / d) - 1
for tc in range(int(input())):
	(x, y) = map(int, input().split())
	ans = 0
	i = 0
	while True:
		temp = noc(x, y, 10 ** i)
		ans += temp
		i += 1
		if temp == 0 or i > 100:
			break
	print(ans)


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd
import bisect
import copy
from itertools import combinations
import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from collections import defaultdict

def fun(n):
	ele = 1
	ini = 0
	ans = n
	while True:
		ele *= 10
		ini += 1
		if ele > n:
			break
		res = n // ele
		ans += res
	return ans
for _ in range(int(input())):
	(l, r) = get_ints()
	print(fun(r) - fun(l))


import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
read = lambda : map(int, input().split())
O = []
for _ in range(int(input())):
	(l, r) = read()
	s = r - l
	while r:
		l //= 10
		r //= 10
		s += r - l
	O.append(str(s))
print('\n'.join(O))


def solve(n):
	temp = 1
	ans = 0
	for i in range(0, 12):
		ans += n // temp
		temp *= 10
	return ans
t = int(input())
(l, r) = (1, 1000000)
for _ in range(t):
	(n1, n2) = map(int, input().split())
	(n1, n2) = (n2, n1)
	(n1, n2) = (n2, n1)
	print(solve(n2) - solve(n1))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return list(map(int, input().split()))

def II():
	return int(input())

def LS():
	return list(input().split())

def S():
	return input()

def solve(x):
	ans = 0
	tmp = 10
	while x > 0:
		ans += x
		x //= 10
	return ans

def main():
	t = II()
	res = list()
	for _ in range(t):
		(l, r) = LI()
		ans = solve(r) - solve(l)
		res.append(ans)
	for ans in res:
		print(ans)
	return 0
main()


t = int(input())
for _ in range(t):
	(l, r) = [int(i) for i in input().split()]
	changed_digits = 0
	while l or r:
		changed_digits += r - l
		l //= 10
		r //= 10
	print(changed_digits)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	while k != 0 or n != 0:
		ans += -n + k
		n = n // 10
		k = k // 10
	print(ans)


def main():

	def solve(arr):
		ans = 0
		(l, r) = arr
		while l > 0 or r > 0:
			ans += r - l
			r = r // 10
			l = l // 10
		return ans
	number_tests = int(input())
	for _ in range(number_tests):
		arr = list(map(int, input().split()))
		print(solve(arr))
main()


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
py = lambda : print('YES')
pn = lambda : print('NO')
t = sInt()
for _ in range(t):
	(l, r) = mInt()
	ans = 0
	while l != 0 or r != 0:
		ans += r - l
		l = l // 10
		r = r // 10
	print(ans)


dic = {10: 11, 100: 111, 1000: 1111, 10000: 11111, 100000: 111111, 1000000: 1111111, 10000000: 11111111, 100000000: 111111111, 1000000000: 1111111111}

def foo(diff):
	start = 0
	ans = 0
	while diff >= test[-1]:
		if diff >= test[start]:
			divisor = diff // test[start]
			ans += dic[test[start]] * divisor
			diff -= divisor * test[start]
		start += 1
		if start > 8:
			break
	ans += diff
	return ans
test = list(dic.keys())
test.sort(reverse=True)
t = int(input())
for i in range(t):
	n = input()
	(l, r) = n.split(' ')
	l = int(l)
	r = int(r)
	rans = foo(r)
	lans = foo(l)
	print(rans - lans)


for _ in [*open(0)][1:]:
	(q, w) = _.split()
	(q, e) = ('000000000' + q, 0)
	for i in range(len(w)):
		e += int(w) - int(q)
		w = w[:-1]
		q = q[:-1]
	print(e)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	r = 0
	while a > 0 or b > 0:
		r += b - a
		a //= 10
		b //= 10
	print(r)


t = int(input())
while t > 0:
	t -= 1
	a = [int(i) for i in input().split(' ')]
	(f, e) = (a[0], a[1])
	out = e - f
	while e > 0:
		out += e // 10 - f // 10
		f //= 10
		e //= 10
	print(out)


import sys
pl = 2
sys.setrecursionlimit(10 ** 5)
if pl:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('outpt.txt', 'w')

def li():
	return [int(xxx) for xxx in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def ff():
	sys.stdout.flush()
t = fi()

def f(a):
	ans = a
	c = ''
	for i in range(11):
		c += '9'
		if int(c) >= a:
			break
		l = 0
		r = 10 ** 10
		res = 0
		while l <= r:
			mid = (l + r) // 2
			if mid * 10 ** len(c) + int(c) < a:
				res = mid + 1
				l = mid + 1
			else:
				r = mid - 1
		ans += res
	return ans
while t > 0:
	t -= 1
	(a, b) = mi()
	print(f(b) - f(a))


import sys
import math
input = sys.stdin.readline
t = int(input())
while t > 0:
	t -= 1
	(l, r) = map(int, input().split())

	def check(n):
		ans = 0
		while n > 0:
			ans += n
			n = n // 10
		return ans
	x = check(r) - check(l)
	print(x)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(L, R) = [int(x) for x in input().split()]
		ans = R - L
		cnt_r = 0
		cnt_l = 0
		for i in range(1, 20):
			cnt_r += R // pow(10, i)
			cnt_l += L // pow(10, i)
		ans += cnt_r - cnt_l
		print(ans)
main()


import heapq, math
from collections import defaultdict, deque
from os import getcwd
import sys, os.path
if os.path.exists('C:/Users/Dhanush/Desktop/cp/input.txt'):
	sys.stdout = open('C:/Users/Dhanush/Desktop/cp/output.txt', 'w')
	sys.stdin = open('C:/Users/Dhanush/Desktop/cp/input.txt', 'r')
input = sys.stdin.readline

def f(n):
	ans = 0
	cur = 10
	mul = 2
	cnt = 0
	while cur <= n:
		ans += n // cur * mul
		cnt += n // cur
		cur = cur * 10
	return ans + n - cnt
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(f(r) - f(l))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def so():
	return int(input())

def st():
	return input()

def mj():
	return map(int, input().strip().split(' '))

def msj():
	return map(str, input().strip().split(' '))

def le():
	return list(map(int, input().split()))

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for i in range(so()):
		(a, b) = mj()
		bec = 0
		mec = 0
		c = 1
		d = 1
		for j in range(12):
			bec += a // c
			c = 10 * c
		for j in range(12):
			mec += b // d
			d = 10 * d
		print(mec - bec)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(l, r) = map(lambda x: int(x), sys.stdin.readline().split())
	count = 0
	while r > l:
		count += r - l
		r = r // 10
		l = l // 10
	print(count)


def f(x):
	r = 0
	while x:
		r += x
		x //= 10
	return r
for s in [*open(0)][1:]:
	(l, r) = map(int, s.split())
	print(f(r) - f(l))


for test in range(int(input())):
	(a, b) = map(int, input().split())
	s = 0
	while b > 0:
		s += b - a
		b = b // 10
		a = a // 10
	print(s)


for _ in range(int(input())):
	oneee = 64656
	(l, r) = map(int, input().split())
	dxds = 3545
	t = r
	zsfv = 6435
	ans = 0
	segdvz = 5844
	a1 = [0] * len(str(t))
	tdgssge = True
	z = str(l)[::-1]
	for i in range(len(str(l))):
		drgdrg = False
		a1[-(i + 1)] = int(z[i])
	sef = 354
	a2 = [int(i) for i in str(t)]
	p1 = str()
	sgv = 58
	p2 = str()
	sefds = 35435
	for i in range(len(a2)):
		dxgv = 3543543
		p1 += str(a2[i])
		xdgvsrv = 3434
		p2 += str(a1[i])
		sgdvsef = 34354
		ans += int(p1) - int(p2)
	afeaesd = 34535
	print(ans)


t = int(input())
ans = []
for i in range(t):
	(l, r) = map(int, input().split())
	res = 0
	for i in range(len(str(r))):
		res += r // 10 ** i - l // 10 ** i
	ans.append(res)
print(*ans, sep='\n')


t = int(input())
out = []

def get_sum(l, r):
	sum = r - l
	dr = r // 10
	dl = l // 10
	while dr > 0:
		sum += dr - dl
		dr = dr // 10
		dl = dl // 10
	return sum
for i in range(t):
	(l, r) = map(int, input().split())
	out.append(get_sum(l, r))
for i in range(t):
	print(out[i])


def ii():
	return int(input())

def mii():
	return map(int, input().split())

def lmii():
	return list(mii())
import math

def main():
	for _ in range(ii()):
		(x, y) = mii()
		ans = y - x
		while y > x:
			y = y // 10
			x = x // 10
			ans += y - x
		print(ans)
main()


import sys
from sys import stdin
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def idk(x):
	ans = 0
	while x:
		ans += x
		x = x // 10
	return ans

def solve():
	pass
for _ in range(int(input())):
	(l, r) = list(map(int, input().split()))
	print(idk(r) - idk(l))


t = int(input())
for i in range(t):
	(l, r) = map(int, input().split())
	res = r - l
	while r // 10 >= 10:
		r //= 10
		l //= 10
		res += r - l
	print(r // 10 - l // 10 + res)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	ans = 0
	while r:
		ans += r - l
		r //= 10
		l //= 10
	print(ans)


s = int(input())
for _ in range(s):
	(l, r) = map(int, input().split(' '))
	change = 0
	while l or r:
		change += r - l
		r = r // 10
		l = l // 10
	print(change)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		(l, r) = get_ints()
		ans = 0
		while r:
			ans += r - l
			r //= 10
			l //= 10
		get_print_int(ans)
solve()


for ii in range(int(input())):
	(l, r) = map(int, input().split())
	cr = 0
	while r != 0:
		cr += r
		r //= 10
	cl = 0
	while l != 0:
		cl += l
		l //= 10
	print(cr - cl)


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	t = r
	ans = 0
	a1 = [0] * len(str(t))
	z = str(l)[::-1]
	for i in range(len(str(l))):
		a1[-(i + 1)] = int(z[i])
	a2 = [int(i) for i in str(t)]
	p1 = str()
	p2 = str()
	for i in range(len(a2)):
		p1 += str(a2[i])
		p2 += str(a1[i])
		ans += int(p1) - int(p2)
	print(ans)


t = int(input())
for w in range(t):
	inp = input().split()
	left = int(inp[0])
	right = int(inp[1])
	ans = 0
	while left > 0 or right > 0:
		ans += right - left
		left = left // 10
		right = right // 10
	print(ans)


for i in range(int(input())):
	(l, r) = list(map(int, input().split()))
	ans = 0
	while l != 0 or r != 0:
		ans += r - l
		l //= 10
		r //= 10
	print(ans)


for testcase in range(int(input())):
	(l, r) = [int(x) for x in input().split()]
	dig = 0
	while r > 0:
		dig = dig + r - l
		r = r // 10
		l = l // 10
	print(dig)


t = int(input())
for _ in range(t):
	(l, r) = list(map(int, input().split()))
	ans = 0
	while l != 0 or r != 0:
		ans += r - l
		l = l // 10
		r = r // 10
	print(ans)


ll = [0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111]
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	x = str(l)
	y = str(r)
	if len(x) == 1:
		ans1 = l
	else:
		b = len(x)
		ans1 = 0
		c = b
		for i in x:
			ans1 += int(i) * ll[c]
			c -= 1
	if len(y) == 1:
		ans2 = r
	else:
		b = len(y)
		ans2 = 0
		c = b
		for i in y:
			ans2 += int(i) * ll[c]
			c -= 1
	print(ans2 - ans1)


import math as m
for i in range(int(input())):
	(r, l) = map(int, input().split())
	ans = 0
	while l >= 1:
		ans += l - r
		r //= 10
		l //= 10
	print(ans)


test_cases = int(input())
for test_case in range(test_cases):
	(l, r) = list(map(int, input().split()))
	ans = 0
	while r > 0:
		ans += r - l
		r = int(r / 10)
		l = int(l / 10)
	print(ans)


t = int(input())
for i in range(t):
	(l, r) = input().split()
	bigger = len(r)
	m = '0' * (bigger - len(l)) + l
	total = int(r) - int(l)
	for j in range(bigger - 1):
		total = total + int(r[:-1 - j]) - int(m[:-1 - j])
	print(total)


for i in range(int(input())):
	(l, r) = map(int, input().split())
	c = 0
	while r > 0:
		c += r - l
		r = r // 10
		l = l // 10
	print(c)


n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	ans = r - l
	ans += r // 10 - l // 10
	ans += r // 100 - l // 100
	ans += r // 1000 - l // 1000
	ans += r // 10000 - l // 10000
	ans += r // 100000 - l // 100000
	ans += r // 1000000 - l // 1000000
	ans += r // 10000000 - l // 10000000
	ans += r // 100000000 - l // 100000000
	ans += r // 1000000000 - l // 1000000000
	ans += r // 10000000000 - l // 10000000000
	ans += r // 100000000000 - l // 100000000000
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()

def f(n):
	(val, ans) = (1, 0)
	while n:
		v = n % 10
		ans += val * v
		n //= 10
		val = 10 * val + 1
	return ans
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(f(r) - f(l))


for t in range(int(input())):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	r = 0
	while y:
		r += y - x
		x //= 10
		y //= 10
	print(r)


t = int(input())
for j in range(t):
	(l, r) = map(int, input().split())
	count = 0
	sum = 0
	ll = str(l)
	sum += 1
	rr = str(r)
	sum += 1
	ll = (len(rr) - len(ll)) * '0' + ll
	sum += 1
	n = len(rr)
	sum += 1
	for i in range(n):
		sum += 1
		s1 = int(ll[:n - i])
		sum += 1
		s2 = int(rr[:n - i])
		sum += 1
		count += s2 - s1
		sum += 1
		i += 1
	print(count)


import os
import sys
from io import BytesIO, IOBase

def solve(x):
	x = list(map(int, str(x)))
	(lx, ans, p) = (len(x), 0, 0)
	for i in range(lx):
		if i == 0:
			ans += x[i]
		else:
			p *= 10
			p += x[i - 1]
			ans += p * 10 + x[i]
	return ans

def main():
	for _ in range(int(input())):
		(l, r) = map(int, input().split())
		print(solve(r) - solve(l))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	c1 = r - l
	for i in range(1, 10):
		c1 += r // 10 ** i
	c2 = 0
	for i in range(1, 10):
		c2 += l // 10 ** i
	print(c1 - c2)


t = int(input())
a = b = c = d = e = f = g = h = j = 0
ans = 0
for i in range(t):
	(ll, r) = input().split(' ')
	(ll, r) = (int(ll), int(r))
	a = r // 10 - ll // 10
	b = r // 100 - ll // 100
	c = r // 1000 - ll // 1000
	d = r // 10000 - ll // 10000
	e = r // 100000 - ll // 100000
	f = r // 1000000 - ll // 1000000
	g = r // 10000000 - ll // 10000000
	h = r // 100000000 - ll // 100000000
	j = r // 1000000000 - ll // 1000000000
	ans = r - ll + a + b + c + d + e + f + g + h + j
	print(ans)
	ans = 0


t = int(input())

def f(x):
	ans = x
	while x > 0:
		x = x // 10
		ans += x
	return ans
for _ in range(t):
	(l, r) = map(int, input().split())
	print(f(r) - f(l))


def num_change(n):
	sum_ = 0
	while n != 0:
		sum_ = sum_ + n
		n = int(n / 10)
	return sum_
T = int(input())
while T != 0:
	(a, b) = map(int, input().split())
	print(num_change(b) - num_change(a))
	T -= 1


def count(s):
	ans = 0
	for i in range(len(s), 0, -1):
		ans += int(s[:i])
	return ans
for t in range(int(input())):
	(l, r) = input().split()
	print(count(r) - count(l))


t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	c = 0
	while l > 0 or r > 0:
		c += r - l
		r = r // 10
		l = l // 10
	print(c)


def sol1toA(A):
	count = A - 1
	while A > 0:
		A = A // 10
		count += A
	return count

def sol(a, b):
	return sol1toA(b) - sol1toA(a)
x = int(input())
for _ in range(x):
	A = list(map(int, input().split()))
	print(sol(A[0], A[1]))


import sys
input = sys.stdin.readline
t = int(input())
c = [1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111]
for _ in range(t):
	(l, r) = map(int, input().split())
	aa = 0
	a = len(str(r))
	r = str(r)
	for i in range(a):
		aa += int(r[i]) * c[a - i - 1]
	bb = 0
	b = len(str(l))
	l = str(l)
	for i in range(b):
		bb += int(l[i]) * c[b - i - 1]
	print(aa - bb)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	t = l
	count = 0
	a = 1
	while t // a > 0:
		count += t // a
		a *= 10
	t = r
	c = 0
	a = 1
	while t // a > 0:
		c += t // a
		a *= 10
	print(c - count)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	first = 0
	second = 0
	for i in range(10):
		first += n // 10 ** i
		second += m // 10 ** i
	print(second - first)


import sys

def calc(a):
	count = 0
	while a > 0:
		count = count + a
		a = int(a / 10)
	return count
t = int(sys.stdin.readline())
while t > 0:
	(l, r) = map(int, sys.stdin.readline().split())
	p = calc(l)
	q = calc(r)
	print(q - p)
	t = t - 1


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	ansl = 0
	ansr = 0
	ansl += l - 1
	ansr += r - 1
	while l:
		ansl += l // 10
		l //= 10
	while r:
		ansr += r // 10
		r //= 10
	print(ansr - ansl)


for i in range(int(input())):
	(r, l) = map(int, input().split())
	ans = 0
	while l >= 1:
		ans += l - r
		r //= 10
		l //= 10
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	ans1 = b
	i = 10
	while i <= b:
		ans1 += b // i
		i *= 10
	ans0 = a
	i = 10
	while i <= a:
		ans0 += a // i
		i *= 10
	print(ans1 - ans0)


def f(l, r):
	if r == 0:
		return 0
	else:
		return r - l + f(l // 10, r // 10)
t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	print(f(l, r))


import sys
import math
from collections import *
from queue import *
MOD = int(1000000000.0 + 7)
input = sys.stdin.readline

def ii():
	return list(map(int, input().strip().split()))

def ist():
	return input().strip().split()
for _ in range(int(input())):
	(a, b) = ii()
	cnt = 0
	while a > 0 or b > 0:
		cnt += b - a
		a = a // 10
		b = b // 10
	print(cnt)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	arr = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]
	ans = 0
	for i in arr:
		ans += r // i - l // i
	print(ans)


import collections
import math
from heapq import *
import bisect
for i in range(int(input())):
	(l, r) = input().split()
	left = right = 0
	l = l[::-1]
	r = r[::-1]
	for i in range(len(l)):
		left += int(l[i] * (i + 1))
	for i in range(len(r)):
		right += int(r[i] * (i + 1))
	print(right - left)


def _i():
	return int(input())

def _f():
	return float(input())

def _iln():
	ln = input().split(' ')
	return [int(i) for i in ln]

def _ln():
	return input().split(' ')

def upto(n):
	k = n
	dp = []
	while n:
		dp.append(n % 10)
		n = (n - dp[-1]) // 10
	n = k
	for i in range(len(dp) - 2, -1, -1):
		dp[i] += sum(dp[i + 1:]) * 9
	return sum(((i + 1) * dp[i] for i in range(len(dp))))

def solve(tt):
	(l, r) = _iln()
	print(upto(r) - upto(l))
t = _i()
for i in range(1, t + 1):
	solve(i)


t = int(input())

def get(idk):
	ans = 0
	temp = idk
	while temp:
		ans += temp
		temp //= 10
	return ans
for _ in range(t):
	(l, r) = map(int, input().split())
	print(get(r) - get(l))


def sum(x):
	s = 0
	i = 1
	while i <= x:
		s += x // i
		i *= 10
	return s
cases = int(input())
for _ in range(cases):
	lr = list(map(int, input().split()))
	print(sum(lr[1]) - sum(lr[0]))


def f(x):
	return sum([x // pow(10, i) for i in range(11)])
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(f(r) - f(l))


from sys import stdin
input = stdin.readline
t = int(input())

def solve(n):
	(res, mul) = (0, 1)
	for i in range(12):
		res += n // mul
		mul = mul * 10
	return res
for _ in range(t):
	(l, r) = map(int, input().split())
	print(solve(r) - solve(l))


import logging
import sys
from inspect import currentframe
input = sys.stdin.readline
logging.basicConfig(level=logging.DEBUG)

def dbg(*args):
	id2names = {id(v): k for (k, v) in currentframe().f_back.f_locals.items()}
	logging.debug(', '.join((id2names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args)))

def solve():
	(l, r) = map(int, input().split())
	s = r - l
	for i in range(1, 10):
		v = pow(10, i) - l % pow(10, i)
		add = 1 + (r - l - v) // pow(10, i)
		if add < 0:
			continue
		s += add
	print(s)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for u in range(int(input())):
	(l, r) = map(int, input().split())
	ans = 0
	f = 1
	while f <= r:
		ans += r // f
		f *= 10
	f = 1
	while f <= l:
		ans -= l // f
		f *= 10
	print(ans)


t = int(input())

def cal(a):
	ans = 0
	num = 1
	while a:
		ans += a
		num *= 10
		a //= 10
	return ans
for tt in range(t):
	(l, r) = [int(i) for i in input().split(' ')]
	print(cal(r) - cal(l))


import sys
try:
	sys.stdin = open('inputf.in', 'r')
	sys.stdout = open('outputf.in', 'w')
except:
	pass
from itertools import permutations, combinations
import heapq
from collections import OrderedDict
import bisect
from functools import cmp_to_key
from collections import deque
import string
from collections import Counter
from collections import defaultdict
from math import sqrt
from queue import PriorityQueue
import sys
from bisect import bisect_left, bisect_right
MOD = 1000000007

def ii():
	return int(sys.stdin.readline().strip())

def si():
	return sys.stdin.readline().strip()

def li():
	return list(map(int, sys.stdin.readline().strip().split()))

def mi():
	return map(int, sys.stdin.readline().strip().split())

def dparr(m, n):
	return [[0] * n for i in range(m)]

def disdp(dp):
	for i in dp:
		print(*i)
t = ii()
for _ in range(t):
	(l, r) = mi()
	lstr = (len(str(r)) - len(str(l))) * '0'
	lstr += str(l)
	ans = 0
	for i in range(0, len(str(r))):
		c1 = int(lstr[0:len(str(r)) - i])
		tempr = str(r)
		c2 = int(tempr[0:len(str(r)) - i])
		ans += c2 - c1
		i += 1
	print(ans)


def foo(n):
	res = 0
	while n > 0:
		res += n
		n = n // 10
	return res
t = int(input())
for _ in range(t):
	(l, r) = list(map(int, input().split()))
	print(foo(r) - foo(l))


def main(l, r):
	res = 0
	while l or r:
		res += r - l
		l //= 10
		r //= 10
	return res
t = int(input().strip())
for _ in range(t):
	(l, r) = map(int, input().strip().split())
	print(main(l, r))


def f(n):
	if n < 10:
		return n
	else:
		return n + f(n // 10)
n = int(input())
for test in range(n):
	(l, r) = map(int, input().split())
	print(f(r) - f(l))


import sys
input = sys.stdin.readline
import bisect
t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	cnt = r - l
	k = 10
	for j in range(10):
		d = r // k - l // k
		cnt += d
		k *= 10
	print(cnt)


def cnt(n):
	res = 0
	while n > 0:
		res += n
		n = n // 10
	return res
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(cnt(r) - cnt(l))


t = int(input())
for _ in range(t):
	[l, r] = [int(x) for x in input().split()]
	ans = 0
	while l != 0 or r != 0:
		ans += r - l
		r //= 10
		l //= 10
	print(ans)


def calc(x):
	f = 1
	ans = []
	while f <= x:
		ans.append(x // f)
		f *= 10
	return sum(ans)
for case in range(int(input())):
	(l, r) = [int(x) for x in input().split()]
	print(calc(r) - calc(l))


def func(n):
	ans = 0
	while n != 0:
		ans += n
		n = n // 10
	return ans
t = int(input())
for _ in range(t):
	(l, r) = [int(i) for i in input().strip().split()]
	print(func(r) - func(l))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	cnt = 0
	while a != 0 or b != 0:
		cnt += b - a
		a //= 10
		b //= 10
	print(cnt)


T = int(input())
for t in range(T):
	(l, r) = map(int, input().split())
	ans = 0
	for i in range(10):
		div = 10 ** i
		ans += r // div - l // div
	print(ans)


t = int(input())
while t:
	(l, r) = map(int, input().split())
	c = r - l
	s = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
	sum = 0
	while c > 0:
		for i in range(10):
			a = c // 10 ** s[i]
			if a > 0:
				c = c - a * 10 ** s[i]
				d = s[i]
				k = r - c
				o = k
				k = list(str(k))
				l = list(str(l))
				K = len(k)
				L = len(l)
				if K == L + 1 and L >= s[i] + 1:
					sum = sum + 1
					K = K - 1
					m = 1
					del k[0]
				if L - s[i] - 1 > 0:
					for p in range(L - s[i] - 1):
						if l[p] != k[p]:
							sum = sum + (L - s[i] - 1 - p)
							break
				for j in range(d + 1):
					sum = sum + a * 10 ** j
				l = o
	print(sum)
	t = t - 1


t = int(input())

def solve():
	(l, r) = map(int, input().split())
	ans = 0
	while r > 0:
		ans += r - l
		r //= 10
		l //= 10
	print(ans)
for i in range(t):
	solve()


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	ans = r - l
	cnt = 0
	x = r
	y = l
	sc = 0
	while y != 0:
		y = y // 10
		sc = sc + y
	while x != 0:
		x = x // 10
		cnt = cnt + x
	print(cnt - sc + ans)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj

def sieve():
	li = [True] * (10 ** 3 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	(prime, cur) = ([0] * 200, 0)
	for i in range(10 ** 3 + 5):
		if li[i] == True:
			prime[cur] = i
			cur += 1
	return prime

def SPF():
	mx = 10 ** 7 + 1
	spf = [mx] * mx
	spf[1] = 1
	for i in range(2, mx):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx, i):
				if i < spf[j]:
					spf[j] = i
	return spf

def prime(n, d):
	while n != 1:
		d[spf[n]] = d.get(spf[n], 0) + 1
		n = n // spf[n]
	return
mod = 1000000007
inf = 1e+18

def solve():
	(l, r) = IP()
	strt = 1
	ans = 0
	while r:
		ans += r - l
		r //= 10
		l //= 10
	print(ans)
	return
t = II()
for i in range(t):
	solve()


def solve():
	(l, r) = map(int, input().split())
	answer = 0
	while r > 0:
		answer += r - l
		r //= 10
		l //= 10
	return answer
t = int(input())
while t > 0:
	t -= 1
	print(solve())


def funct(l, r):
	out = 0
	for i in range(0, 13):
		f = 10 ** i
		out = out + (r // f - l // f)
	return out
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(funct(l, r))


t = int(input())
for jj in range(t):
	(l, r) = list(map(int, input().split()))
	l = str(l)
	r = str(r)
	while len(l) != len(r):
		l = '0' + l
	ans = 0
	old = 0
	for i in range(len(l)):
		diff = int(r[i]) - int(l[i])
		ans += old * 10 + diff
		old = old * 10 + diff
	print(ans)


def s(n):
	l = len(str(n))
	ret = 0
	for i in str(n):
		ret += int(i * l)
		l -= 1
	return ret
for _ in range(int(input())):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	print(s(b) - s(a))


import os
import sys
import math
import collections
import functools
import itertools
import heapq
import bisect
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcde'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def INT():
	return int(input())

def STR():
	return input()

def INTs():
	return tuple(map(int, input().split()))

def ARRINT():
	return [int(i) for i in input().split()]

def ARRSTR():
	return [i for i in input().split()]

def solve(l, r):

	def cnt(n):
		res = 0
		while n > 0:
			res += n
			n //= 10
		return res
	print(cnt(r) - cnt(l))
for _ in range(INT()):
	(l, r) = INTs()
	solve(l, r)


a = int(input())
for i in range(a):
	s = input()
	s = s.split()
	(num1, num2) = (int(s[0]), int(s[1]))
	digit = 0
	ans = 0
	while True:
		cnt = num2 // 10 ** digit - num1 // 10 ** digit
		if cnt == 0:
			break
		ans += cnt
		digit += 1
	print(ans)


from sys import stdin
from sys import stdout
from math import *
import sys
input = stdin.readline
prev = 11
x = 10
a = []
b = []
for i in range(1, 10):
	last = prev
	y = x
	for j in range(10):
		if j == 9:
			a.append(last + 1)
			b.append(y)
		else:
			a.append(last)
			b.append(y)
			if i != 1 and j == 0:
				a.pop()
				b.pop()
		last += prev
		y += x
	prev = a[-1]
	x = b[-1]
d = {}
for i in range(len(a)):
	d[b[i]] = a[i]

def f(n):
	ans = 0
	for i in range(9, 0, -1):
		if n == 0:
			break
		x = 10 ** i
		if n % x != n:
			ans += d[x] * (n // x)
			n = n % x
	return ans + n
for __ in range(int(input())):
	(a, b) = map(int, input().split())
	x = f(a)
	y = f(b)
	print(y - x)


p = int(input())
for o in range(p):
	(n, m) = map(int, input().strip().split())
	ans = 0
	while m > 0:
		ans += m - n
		m = m // 10
		n = n // 10
	print(ans)


from typing import Tuple

def calculate_delta(l: int, r: int) -> int:
	result = 0
	while l:
		result += r - l
		l //= 10
		r //= 10
	while r:
		result += r
		r //= 10
	return result

def read_numbers() -> Tuple[int, int]:
	data = input().split(' ')
	return (int(data[0]), int(data[1]))

def main():
	results = []
	for _ in range(int(input())):
		results.append(calculate_delta(*read_numbers()))
	for r in results:
		print(r)
main()


t = int(input())
for i in range(0, t):
	(l, r) = map(int, input().split())
	a = 0
	while l != 0 or r != 0:
		a = a + abs(l - r)
		l //= 10
		r //= 10
	print(a)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = m - n
	while m != 0:
		ans += m // 10 - n // 10
		m = m // 10
		n = n // 10
	print(ans)


import sys
input = sys.stdin.readline

def f(a):
	ok = 0
	while a > 0:
		ok += a
		a = a // 10
	return ok
t = int(input())
for you in range(t):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	print(f(b) - f(a))


for s in [*open(0)][1:]:
	r = 0
	k = -1
	for x in map(int, s.split()):
		while x:
			r += k * x
			x //= 10
		k = 1
	print(r)


import sys
input = sys.stdin.readline
T = int(input())
for i in range(T):
	(n, m) = map(int, input().split())
	s = 0
	while m:
		s += m
		m = m // 10
	while n:
		s -= n
		n = n // 10
	print(s)


k = int(input())
for x in range(k):
	ans = 0
	x = str(input())
	x = x.split()
	r = int(x[1])
	l = int(x[0])
	while r != 0 or l != 0:
		ans += r - l
		l = l // 10
		r = r // 10
	k += 1
	if k == 1:
		print()
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(l, r) = [int(x) for x in input().split()]
	num1 = str(l)
	num2 = str(r)
	ans = 0
	while len(num1) != len(num2):
		num1 = '0' + num1
	for i in range(len(num1)):
		k1 = int(num1[:i + 1])
		k2 = int(num2[:i + 1])
		ans += k2 - k1
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(str, input().split())
	a = a[::-1]
	b = b[::-1]
	aa = 0
	bb = 0
	for i in range(len(b)):
		bb += int((i + 1) * '1') * int(b[i])
	for i in range(len(a)):
		aa += int((i + 1) * '1') * int(a[i])
	print(bb - aa)


n = int(input())
while n:
	(a, b) = list(map(int, input().split()))
	ans = 0
	cnt = 0
	while b:
		q = b % 10
		q = 10 if not q else q
		ans += b - a
		b //= 10
		a //= 10
		cnt += 1
	print(ans)
	n -= 1


from sys import stdout, stdin, setrecursionlimit
from bisect import insort, bisect_right, bisect_left
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = 1
num = getInt()
for _ in range(num):
	(x, y) = zzz()
	ans = y - x
	while x < y:
		x //= 10
		y //= 10
		ans += y - x
	print(ans)


def solve(l, r):
	ans = 0
	while l != 0 or r != 0:
		ans += r - l
		l //= 10
		r //= 10
	return ans
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(solve(l, r))


from collections import defaultdict

def main():
	for _ in range(int(input())):
		(l, r) = list(map(int, input().split()))
		l = str(l)
		r = str(r)
		ans = 0
		r_ = len(r)
		l_ = len(l)
		s = '1'
		for i in range(r_):
			z = int(s * (r_ - i))
			ans += z * int(r[i])
		for i in range(l_):
			z = int(s * (l_ - i))
			ans -= z * int(l[i])
		print(ans)
div = [0] * 1000001

def NumOfDivisors(n):
	for i in range(1, n + 1):
		for j in range(i, n + 1, i):
			div[j] += 1

def primes1(n):
	sieve = [True] * (n // 2)
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i // 2]:
			sieve[i * i // 2::i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [2 * i + 1 for i in range(1, n // 2) if sieve[i]]

def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)

class Graph:

	def __init__(self):
		self.Graph = defaultdict(list)

	def addEdge(self, u, v):
		self.Graph[u].append(v)
		self.Graph[v].append(u)

	def DFSUtil(self, v, visited):
		visited.add(v)
		for neighbour in self.Graph[v]:
			if neighbour not in visited:
				self.DFSUtil(neighbour, visited)

	def DFS(self, v):
		visited = set()
		self.DFSUtil(v, visited)

	def BFS(self, s):
		visited = set()
		queue = []
		queue.append(s)
		visited.add(s)
		while queue:
			s = queue.pop(0)
			for i in self.Graph[s]:
				if i not in visited:
					queue.append(i)
					visited.add(i)
main()


t = t = int(input().strip())
for _ in range(t):
	(l, r) = map(int, input().strip().split())
	(ans, ok) = (0, 1)
	while ok <= r:
		ans += r // ok - l // ok
		ok *= 10
	print(ans)


t = int(input())
for i in range(t):
	(l, r) = map(int, input().strip().split(' '))

	def calculate(n):
		n = str(n)
		res = 0
		for i in range(len(n) - 1):
			res += int(n[i] * (len(n) - i - 1))
		res += int(n)
		return res
	print(calculate(r) - calculate(l))


t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	s = 0
	while r > 0:
		s += r - l
		r //= 10
		l //= 10
	print(s)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans = 0
	while x != 0 or y != 0:
		ans += y - x
		x //= 10
		y //= 10
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	ans = 0
	while l > 0 or r > 0:
		ans += r - l
		r = r // 10
		l = l // 10
	print(ans)


def fun(n):
	(s, c) = (10, n - 1)
	while s <= n:
		c += n // s
		s *= 10
	return c
for _ in range(int(input())):
	(l, r) = list(map(int, input().split()))
	print(fun(r) - fun(l))


d = [0, 10, 110, 1110, 11110, 111110, 1111110, 11111110, 111111110, 1111111110, 11111111110, 111111111110]
t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	lans = 0
	rans = 0
	mult = 1
	count = 0
	while l > 0:
		ldigit = l % 10
		if ldigit > 0:
			count += 1
			lans += ldigit * d[mult - 1] + (ldigit - 1)
		l = int(l / 10)
		mult = mult + 1
	lans += count - 1
	mult = 1
	count = 0
	while r > 0:
		ldigit = r % 10
		if ldigit > 0:
			count += 1
			rans += ldigit * d[mult - 1] + (ldigit - 1)
		r = int(r / 10)
		mult = mult + 1
	rans += count - 1
	print(rans - lans)


def count(n):
	ans = n // 10 + n // 100 + n // 1000 + n // 10000 + +(n // 100000) + n // 1000000 + n // 10000000 + n // 100000000 + n // 1000000000
	return ans
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	left = a + count(a)
	right = b + count(b)
	print(right - left)


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(l, r) = map(int, stdin.readline().split())
	ans = 0
	while r > 0:
		ans += r - l
		r //= 10
		l //= 10
	print(ans)


from math import gcd
t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	cnt = 0
	while r >= 1:
		cnt += r
		r //= 10
	while l >= 1:
		cnt -= l
		l //= 10
	print(cnt)


def interesting_function(l, r):
	result = 0
	while r > 0:
		result += r - l
		r //= 10
		l //= 10
	print(result)
t = int(input())
for _ in range(t):
	inputs = list(map(str, input().split()))
	interesting_function(int(inputs[0]), int(inputs[1]))


t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	n = len(str(r))
	ans = 0
	for i in range(n):
		currl = l // 10 ** i
		currr = r // 10 ** i
		ans += currr - currl
	print(ans)


for _ in range(int(input())):
	(l, r) = input().split()
	l = '0' * (len(r) - len(l)) + l
	out = 0
	for i in range(len(r)):
		out += int(r[:len(r) - i]) - int(l[:len(r) - i])
	print(out)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	s = int('1' + (len(str(r)) - 1) * '0')
	i = s
	prev = 0
	ans = 0
	prod = len(str(s))
	while i > 0:
		boom = r // i - l // i - prev
		prev += boom
		ans += boom * prod
		i //= 10
		prod -= 1
	print(ans)


t = int(input())
for i in range(t):
	(l, r) = map(str, input().split())
	(ans, pres) = (0, 0)
	while len(l) < len(r):
		l = '0' + l
	for i in range(len(l)):
		if l[i] == r[i] and pres == 0:
			continue
		el1 = int(l[i])
		el2 = int(r[i])
		if pres == 0:
			ans = el2 - el1
			pres = ans
		else:
			temp = 10 - el1 + (pres - 1) * 10 + el2
			ans += temp
			pres = temp
	print(ans)


from collections import Counter, defaultdict, deque
import math
from heapq import *
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7

def solve():
	(a, b) = [int(x) for x in input().split()]
	total = b - a
	res = 0
	for i in range(11):
		d = b // 10 ** i - a // 10 ** i
		res += d
	print(res)
tt = int(input())
for test in range(tt):
	solve()


a = int(input())
for _ in range(a):
	inp = input().split()
	l = 0
	r = 0
	l = int(inp[0])
	r = int(inp[1])
	ans = 0
	while l + r > 0:
		ans += l - r
		l = l // 10
		r = r // 10
	if ans <= 1111111110:
		ans = abs(ans)
	print(ans)


def main():
	ans = []
	for _ in range(int(input())):
		(l, t) = map(int, input().split())
		cha = 0
		while t > 0:
			cha += t - l
			l //= 10
			t //= 10
		ans.append(cha)
	for i in ans:
		print(i)
main()


for _ in range(int(input())):
	(a, b) = map(str, input().split())
	x = a[::-1]
	y = b[::-1]
	n = len(x)
	m = len(b)
	l = [1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111]
	ans = 0
	for i in range(m):
		c = ord(y[i]) - 48
		ans += c * l[i]
	for i in range(n):
		c = ord(x[i]) - 48
		ans -= c * l[i]
	print(ans)


import sys
input = sys.stdin.readline
a = [(0, 0), (2, 0), (0, 0), (2, 1)]
h = [(1, 0), (1, 0), (3, 0), (1, 0)]
z = [(0, 0), (0, 0), (0, 0), (0, 0)]

def f_s(x):
	r = 0
	for i in range(1, x + 1):
		si = str(i)
		sii = str(i - 1)
		if len(si) > len(sii):
			sii = '0' + sii
		for j in range(len(si)):
			r += si[j] != sii[j]
	return r

def f(x):
	r = x
	while x != 0:
		x //= 10
		r += x
	return r

def solve():
	(l, r) = map(int, input().split())
	print(f(r) - f(l))
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	(l, r) = list(map(int, input().split()))
	cnt = 0
	for i in range(11):
		cnt += r // pow(10, i)
	cnt2 = 0
	for i in range(11):
		cnt2 += l // pow(10, i)
	print(cnt - cnt2)


t = int(input())
for w in range(t):
	(l, r) = [x for x in input().split()]
	a = [int(x) for x in l]
	b = [int(x) for x in r]
	count = 0
	while len(a) > 0 or len(b) > 0:
		s_a = 0
		s_b = 0
		for i in range(len(a)):
			s_a += a[i]
			s_a *= 10
		for i in range(len(b)):
			s_b += b[i]
			s_b *= 10
		s_a //= 10
		s_b //= 10
		count += s_b - s_a
		if len(a) > 0:
			a.pop()
		b.pop()
	print(count)


t = int(input())
for i in range(t):
	x = input()
	l = int(x.split()[0])
	r = int(x.split()[1])
	if r // 10 == 0 and l // 10 == 0:
		print(r - l)
		continue
	k = r
	while k // 10 >= 1:
		r += k // 10
		k = k // 10
	k = l
	while k // 10 >= 1:
		l += k // 10
		k = k // 10
	print(r - l)
	continue


t = int(input())
for z in range(t):
	(l, r) = map(int, input().split())
	ans = 0
	x = str(l)[::-1]
	y = str(r)[::-1]
	for i in range(0, len(y)):
		s = int('1' * (i + 1))
		tp1 = int(y[i]) % 10 ** (i + 1)
		ans += tp1 * s
	for i in range(0, len(x)):
		s = int('1' * (i + 1))
		tp1 = int(x[i]) % 10 ** (i + 1)
		ans -= tp1 * s
	print(ans)


from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
L = lambda : list(M())
mod = 1000000007
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	(l1, l2) = M()
	j1 = j2 = 0
	k1 = k2 = 1
	for i in range(12):
		j1 = j1 + l1 // k1
		j2 = j2 + l2 // k2
		k1 *= 10
		k2 *= 10
	print(j2 - j1)
tt = 1
tt = I()
for _ in range(tt):
	solve()


for _ in range(int(input())):
	(a, b) = input().split()
	(m, n) = (len(a), len(b))
	a = '0' * (n - m) + a
	ans = 0
	for i in range(1, 1 + len(b)):
		ans += int(b[:i]) - int(a[:i])
	print(ans)


t = int(input())
for i in range(t):
	(l, r) = map(int, input().split())
	change = 0
	while r:
		change += r - l
		r = r // 10
		l = l // 10
	print(change)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	count = r - l
	while r:
		count += r // 10
		r //= 10
	while l:
		count -= l // 10
		l //= 10
	print(count)


for _ in range(int(input())):
	(l, r) = list(map(int, input().split(' ')))
	res = r - l
	while r > 0:
		r //= 10
		l //= 10
		res += r - l
	print(res)


def func(r):
	if r == 1:
		return 0
	total_digits = len(str(r))
	nums_divisible_by_ten = [0 for i in range(total_digits + 1)]
	starting = total_digits - 1
	count = 0
	while starting > 0:
		divisor = 10 ** starting
		nums_divisible_by_ten[starting] = r // divisor - count
		count = r // divisor
		starting -= 1
	total_sum = 0
	for j in range(1, total_digits + 1):
		total_sum += nums_divisible_by_ten[j] * (j + 1)
	total_sum += r - sum(nums_divisible_by_ten) - 1
	return total_sum
t = int(input())
for i in range(t):
	(l, r) = map(int, input().split())
	print(func(r) - func(l))


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	nl = len(str(l))
	rl = len(str(r))
	ansl = l % 10 + 11 * (l // 10)
	ansr = r % 10 + 11 * (r // 10)
	for i in range(2, nl):
		temp = 10 ** i
		ansl += l // temp
	for i in range(2, rl):
		temp = 10 ** i
		ansr += r // temp
	print(ansr - ansl)


from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
mod = 1000000007
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	ans = 0
	c = 0
	while l != 0 or r != 0:
		ans += r - l
		l //= 10
		r //= 10
		c += 1
	print(ans)


import math
import collections
from itertools import permutations
from itertools import combinations

def prob():
	(l, r) = [int(x) for x in input().split()]
	ans = 0
	while l > 0 or r > 0:
		ans += r - l
		l = l // 10
		r = r // 10
	print(ans)
t = 1
t = int(input())
for _ in range(0, t):
	prob()


T = int(input())
for _ in range(T):
	(a, b) = input().split()
	n = len(b)
	a = a.zfill(n)
	i = 0
	while i < n and a[i] == b[i]:
		i += 1
	if i == n:
		print(0)
		continue
	cost = 0
	i = n - 1
	delta = 1
	carry = 0
	while i > 0:
		if carry or a[i] != '0':
			cost += delta * (10 - int(a[i]) - carry) + 1
			carry = 1
		delta = delta * 10 + 1
		i -= 1
	cost += delta * (int(b[0]) - int(a[0]) - carry)
	delta //= 10
	for i in range(1, n):
		cost += delta * int(b[i])
		delta //= 10
	print(cost)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	x = r - l
	y = x + (r // 10 - l // 10) + (r // 100 - l // 100) + (r // 1000 - l // 1000) + (r // 10000 - l // 10000) + (r // 100000 - l // 100000) + (r // 1000000 - l // 1000000) + (r // 10000000 - l // 10000000) + (r // 100000000 - l // 100000000) + (r // 1000000000 - l // 1000000000)
	print(y)


for i in range(int(input())):
	(l, r) = list(map(int, input().split()))
	a = 0
	b = 0
	for i in range(1, 10):
		a += l // 10 ** i
		b += r // 10 ** i
	print(b - a + r - l)


t = int(input())
for tt in range(t):
	(l, r) = input().strip().split(' ')
	l = int(l)
	r = int(r)
	ll = l // 10
	rr = r // 10
	while ll:
		l += ll
		ll = ll // 10
	while rr:
		r += rr
		rr = rr // 10
	print(r - l)