fork download
  1. import math
  2. def ip():
  3. return map(int,input().split())
  4. def f(x):
  5.  
  6. lst=[]
  7.  
  8. i=1
  9. while True:
  10. if x>=(10**i):
  11. lst.append(x//(10**i-1))
  12. i+=1
  13. else:
  14. break
  15.  
  16. if len(lst)==0:
  17. return 0
  18.  
  19. n=len(lst)
  20. sm=lst[-1]*n
  21. for i in range(n-2,-1,-1):
  22. lst[i]-=sm
  23. sm+=lst[i]*(i+1)
  24.  
  25. ct=0
  26. for i in range(n):
  27. ct+=(i+1)*lst[i]
  28.  
  29. return ct
  30.  
  31.  
  32.  
  33. T=int(input())
  34. # T=1
  35. for __ in range(T):
  36. l,r=ip()
  37. print(r-l+f(r-1)-f(l-1))
Success #stdin #stdout 0.13s 14108KB
stdin
4
1 9
9 10
10 20
1 1000000000
stdout
8
1
12
1111111110