For a non-negative integer N, define S(N) as the sum of the odd digits of N
plus twice the sum of the even digits of N.
For example, S(5)=5, S(456)=2*4+5+2*6=25, and S(314159)=3+1+2*4+1+5+9=27.
Define D(N) as the last digit of S(N).
So D(5)=5, D(456)=5, and D(314159)=7.
Given 2 non-negative integers A and B, compute the sum of D(N) over all N between A and B, inclusive.

------ Input ------ 

Input will begin with an integer T, the number of test cases.
T lines follow, each containing 2 integers A and B.

------ Output ------ 

For each test case, output a single integer indicating the corresponding sum.

------ Constraints ------ 

$T ≤ 1000$
$0 ≤ A ≤ B ≤ 400,000,000$

----- Sample Input 1 ------ 
3
1 8
28 138
314159 314159
----- Sample Output 1 ------ 
36
495
7

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
def getA(i):
	ans = 0
	while i > 0:
		dig = i % 10
		if dig & 1:
			ans += dig
		else:
			ans += dig * 2
		i = int(i / 10)
	return ans

def getAns(A):
	if A <= 0:
		return 0
	ans = 0
	while A % 10 != 0:
		ans += int(getA(A) % 10)
		A -= 1
	return ans + 45 * int(A / 10) + getA(A) % 10
for tc in range(int(input().strip())):
	(A, B) = map(int, input().strip().split())
	print(getAns(B) - getAns(A - 1))


def D(n):
	return sum([int(x) if int(x) % 2 == 1 else 2 * int(x) for x in str(n)]) % 10
t = int(input())
for _ in range(t):
	ans = 0
	(a, b) = map(int, input().split())
	while a < b and a % 10:
		ans += D(a)
		a += 1
	while a < b and b % 10:
		ans += D(b)
		b -= 1
	ans += (b - a) // 10 * 45
	ans += D(b)
	print(ans)


def dd(x):
	s = 0
	while x != 0:
		r = x % 10
		x = x // 10
		if r % 2 == 0:
			s += r * 2
		else:
			s += r
	return s % 10

def calc(x):
	res = 0
	while x % 10 != 0:
		x = x - 1
		res += dd(x)
	return res + 45 * x // 10
t = int(input())
for it in range(t):
	(a, b) = map(int, input().split())
	print(calc(b + 1) - calc(a))


def snek(x):
	s = 0
	while x != 0:
		r = x % 10
		x //= 10
		if r % 2 == 0:
			s += r * 2
		else:
			s += r
	return s % 10

def calc(x):
	y = 0
	while x % 10 != 0:
		x -= 1
		y += snek(x)
	return y + 45 * x // 10
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(calc(b + 1) - calc(a))


def D(n):
	arr = [0, 1, 4, 3, 8, 5, 2, 7, 6, 9]
	if n < 10:
		return arr[n]
	else:
		return (D(n // 10) + D(n % 10)) % 10

def C(n):
	if n % 10 == 0:
		return 45 * int(n / 10)
	else:
		return C(n - 1) + D(n - 1)
for t in range(0, int(input())):
	(a, b) = map(int, input().split())
	print(C(b + 1) - C(a))


import math

def val(a, b):
	k = 0
	for i in range(a, b + 1):
		sum1 = 0
		l1 = list(map(int, str(i)))
		for j in range(len(l1)):
			if l1[j] % 2 == 0:
				sum1 = sum1 + l1[j]
		sum1 += sum(l1)
		k += sum1 % 10
	return k
t = int(input())
while t != 0:
	t -= 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	k = 0
	if b - a <= 10:
		for i in range(a, b + 1):
			sum1 = 0
			l1 = list(map(int, str(i)))
			for j in range(len(l1)):
				if l1[j] % 2 == 0:
					sum1 = sum1 + l1[j]
			sum1 += sum(l1)
			k += sum1 % 10
		print(k)
	else:
		p = b // 10 * 10
		l = (a // 10 + 1) * 10
		sul = val(a, l - 1) + val(p, b)
		print(sul + (p - l) // 10 * 45)


def computesum(n):
	sum = 0
	while n != 0:
		t = n % 10
		if t % 2 == 0:
			t *= 2
		sum += t
		n = n // 10
	return sum % 10
m = int(input())
for d in range(m):
	(L, R) = map(int, input().split())
	l = L
	r = R
	sum = 0
	while L % 10 != 0 and L <= R:
		sum += computesum(L)
		L += 1
	while R % 10 != 0 and R > L:
		sum += computesum(R)
		R -= 1
	if R > L:
		sum += computesum(R)
	if r - l > 10:
		sum += (R - L) // 10 * 45
	print(sum)


def d(n):
	s = 0
	while n:
		if n % 10 % 2 == 0:
			s += 2 * (n % 10)
		else:
			s += n % 10
		n = n // 10
	return s % 10
for i in range(int(input())):
	(l, r) = map(int, input().split())
	D1 = 0
	D2 = 0
	if l == r:
		print(d(l))
	else:
		D1 = r // 10 * 45
		D2 = l // 10 * 45
		for j in range(r - r % 10, r + 1):
			D1 += d(j)
		for j in range(l - l % 10, l):
			D2 += d(j)
		print(D1 - D2)