https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWO6cgzKOIEDFAWw
def calc_floor(x):
'''
4가 들어가는 층을 제외하고 카운트
ex) 110
101~110의 경우: 101, 102, 103, 105, 106, 107, 108, 109, 110 => 9개
1~100의 경우: 1~10, 11~20, 21~30, 31~39, 50~60, 61~70, 71~80, 81~90, 91~100, 101~110 => 9개*9 => 9 ** 2
'''
square = 0
floors = 0
while x > 0:
x, remainder = divmod(x, 10)
floors += (remainder - 1) * (9 ** square) if remainder >= 4 else remainder * (9 ** square)
square += 1
return floors
T = int(input())
for tc in range(1, T+1):
A, B = map(int, input().split())
a = calc_floor(abs(A))
b = calc_floor(abs(B))
if A < 0 < B:
result = a + b - 1 # 0층 빼줌
else:
result = abs(b - a)
print('#{} {}'.format(tc, result))