Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible by $m$ are $5, 10, 15$. Their last digits are $5, 0, 5$ correspondingly, their sum is $10$.

Your task is to calculate the sum of all digits Polycarp has written down.

You have to answer $q$ independent queries.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 1000$) — the number of queries.

The following $q$ lines contain queries, one per line. Each query is given as two integers $n$ and $m$ ($1 \le n, m \le 10^{16}$) — the number of pages in the book and required divisor, respectively.


-----Output-----

For each query print the answer for it — the sum of digits written down by Polycarp.


-----Example-----
Input
7
1 1
10 1
100 3
1024 14
998244353 1337
123 144
1234312817382646 13

Output
1
45
153
294
3359835
0
427262129093995

Difficulty: introductory

Starter code:

Solutions:
for _ in range(int(input())):
    n, m = list(map(int, input().split()))
    A = []
    x = 1
    while True:
        if (m * x) % 10 not in A:
            A.append((m * x) % 10)
        else:
            break
        x += 1
    s = sum(A)
    n //= m
    print(s * (n // len(A)) + sum(A[:n % len(A)]))


import math
tst = int(input())
for _ in range(tst):
    b, a = list(map(int, input().split()))
    b //= a
    cnt = b // 10
    sum = 0
    for i in range(1, 11):
        sum += (a * i) % 10
    sum *= cnt
    for i in range(1, b % 10 + 1):
        sum += (a * i) % 10
    print(sum)



# Contest: Codeforces Round #582 (Div. 3) (https://codeforces.com/contest/1213)
# Problem: C: Book Reading (https://codeforces.com/contest/1213/problem/C)

def rint():
    return int(input())


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


from math import gcd
q = rint()
for _ in range(q):
    n, m = rints()
    lcm = 10 * m // gcd(10, m)
    block = 0
    for i in range(lcm // m):
        block += (i + 1) * m % 10
    n_block = n // lcm
    tot = n_block * block
    for i in range(n_block * lcm, n + 1, m):
        tot += i % 10
    print(tot)


q = int(input())
s = [0] * 10
for i in range(10):
    for j in range(10):
        s[i] += (j * i) % 10

for i in range(q):
    n, m = list(map(int, input().split()))
    pages = n // m
    ans = s[m % 10] * (pages // 10)
    pages %= 10
    m %= 10
    for i in range(pages + 1):
        ans += (m * i) % 10
    print(ans)


# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
import math
import copy
 
T = int(input())
#N = int(input())
#s1 = input()
#s2 = input()
#N,Q = [int(x) for x in stdin.readline().split()]
#arr = [int(x) for x in stdin.readline().split()]

for i in range(T):
    N,M = [int(x) for x in stdin.readline().split()]
    
    d = M%10
    
    q = N//M
    
    tail = []
    
    t = 0
    while True:
        t = (t + d)%10
        if t not in tail:
            tail.append(t)
        else:
            break
            
    L = len(tail)
    
    s = sum(tail)
    q2 = q//L
    r = q%L
    
    #print(q2,r)
    print(q2*s+sum(tail[:r]))

for TT in range(1, int(input()) + 1):
    n, m = map(int, input().split())
    x = (n // m) + 1
    l = [0]
    while True:
        d = (l[-1] + m) % 10
        if d in l: break
        l.append(d)
    n = len(l)
    a, b = x // n, x % n
    print(sum(l) * a + sum(l[:b]))

q=int(input())
for _ in range(q):
  n,m=list(map(int,input().split()))
  a,b=divmod(n//m,10)
  ans=0
  ans_t=0
  for i in range(1,b+1):
    ans+=(i*m)%10
  for i in range(1,10):
    ans_t+=(i*m)%10
  print(ans+ans_t*a)




for q in range(int(input())):
    n, m = list(map(int, input().split()))
    if m % 10 == 0:
        print(0)
    elif m % 10 == 5:
        print((n//m+1)//2*5)
    elif m % 2 == 0:
        x = n//(m*5)*m*5
        ans = n//(m*5)*20
        while x <= n:
            ans += x % 10
            x += m
        print(ans)
    else:
        x = n // (m * 10) * m * 10
        ans = n // (m * 10)*45
        while x <= n:
            ans += x % 10
            x += m
        print(ans)


for _ in range(int(input())):
    
    a,b=[int(i) for i in input().split()]
    tot=0
    ans=[]
    for i in range(1,11):
        ans.append(int(str(b*i)[-1]))
    tot=sum(ans)
    x=a//b
    y=x%10
    x=x//10
    ans=tot*x+sum(ans[:y])
    print(ans)

#582_C

n = int(input())

ref = []
sums = []
for i in range(0, 10):
    ref.append([])
    for j in range(0, 10):
        ref[-1].append(int(list(str(i * j))[-1]))
    sums.append(sum(ref[-1]))

pref = []
for i in ref:
    pref.append([i[0]])
    for j in range(1, len(i)):
        pref[-1].append(pref[-1][-1] + i[j])

for i in range(0, n):
    ln = [int(j) for j in input().split(" ")]
    a = ln[0]
    b = ln[1]
    dig = int(list(str(b))[-1])
    ct = a // (b * 10)
    rem = (a % (b * 10)) // b
    print(ct * sums[dig] + pref[dig][rem])


from sys import stdin
t=int(stdin.readline().strip())
for j in range(t):
    n,m=list(map(int,stdin.readline().strip().split()))
    vis=[False for i in range(10)]
    x=m%10
    s=[]
    while vis[x]!=True:
        vis[x]=True
        s.append(x)
        x=(x+m)%10
    y=n//m
    ans=0
    z=(y//len(s))*len(s)
    ans+=sum(s)*(y//len(s))
    d=y-z
    for i in range(d):
        ans+=s[i]
    print(ans)
    
    
    
    
        
            
    


'''input
7
1 1
10 1
100 3
1024 14
998244353 1337
123 144
1234312817382646 13

'''
import sys
from collections import defaultdict as dd
from itertools import  permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from  heapq import heappush as hpush
from heapq import heappop as hpop
mod=10**9+7

def ri(flag=0):
	if flag==0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())


for _ in range(ri(1)):
	n,m= ri()
	k = []
	for i in range(m,n+1,m):
		temp = i%10
		if temp not in k:
			k.append(temp)
		else:
			break
	
	period = n//m
	ans =0
	if len(k)!=0:
		ans = sum(k)*(period//len(k))
		rem = period %len(k)

		for i in range(rem):
			ans += k[i]

	print(ans)
	#print(k,period)


t = int(input())
for _ in range(t):
    n, m = list(map(int, input().split()))
    if n < m:
        print(0)
        continue
    dct = dict()

    sum, cnt = 0, 0
    cur = m
    ans = 0
    while cur <= n:
        c = cur % 10
        if c in dct and cur + 10 * m <= n:
            per_sum, per_cnt = sum - dct[c][0], cnt - dct[c][1]
            cycles = (n // m - (cur - 1) // m) // per_cnt
            ans += per_sum * cycles
            cur += cycles * m * per_cnt
        else:
            dct[c] = (sum, cnt)
            ans += c
            cur += m
            sum += c
            cnt += 1
    print(ans)



q = int(input())
for test in range(q):
    n,m = input().split()
    n = int(n)
    m = int(m)
    sumoften = 0
    for j in range(1,10):
        sumoften += (m*j) % 10
    div = n // m
    ans = sumoften * (div // 10)
    for j in range(1,(div % 10) + 1):
        ans += (m*j) % 10
    print(ans)

Global_data = [(1, 0), (10, 45), (5, 20), (10, 45), (5, 20), (2, 5), (5, 20), (10, 45), (5, 20), (10, 45)]
n = int(input())
for i in range(n):
    a, b = map(int, input().split())
    kol = a // b
    last = b % 10
    ans = kol // Global_data[last][0] * Global_data[last][1]
    c = 0
    for i in range(kol % Global_data[last][0]):
        c += last
        c %= 10
        ans += c
    print(ans)

q=int(input())
for _ in range(q):
    n,m=list(map(int,input().split()))
    x=n//m
    y=x%10
    if (m%10)==0:
        print(0)
        continue
    d=m%10
    if d==5:
        tot=(x//2)*5
        if x%2==1:
            tot+=5
        print(tot)
        continue
    if d%2==0:
        tot=(x//10)*40
        for i in range(y):
            tot+=(m*(i+1))%10
    elif d%2==1:
        tot=(x//10)*45
        for i in range(y):
            tot+=(m*(i+1))%10
    print(tot)
        


from sys import stdin, stdout

input = stdin.readline

t = int(input())
while t:
    t -= 1
    n, m = list(map(int, input().split()))

    a = []
    for i in range(1, 11, 1):
        a.append((m * i) % 10)

    sum = 0
    for i in a:
        sum += i

    x = n // m
    res = (x // 10) * sum
    x %= 10
    for i in range(x):
        res += a[i]

    print(res)


t = int(input())
for z in range(t):
    n, m = map(int, input().split())
    if m > n:
        print(0)
        continue
    use = []
    x = m
    for i in range(20):
        use.append(x % 10)
        x += m
    #print(use)
    arr = []
    for i in range(len(use)):
        if not use[i] in arr:
            arr.append(use[i])
        else:
            break

    l = len(arr)
    cnt = n // (l * m)
    left = (n % (l * m)) // m
    print(cnt * sum(arr) + sum(arr[:left]))

t = int(input())
for test in range(t):
    n, m = map(int, input().split())
    length = 1
    a = [0] * 10
    cur = m % 10
    a[cur] = 1
    s = cur
    while True:
        cur += m
        cur %= 10
        if a[cur] == 1:
            break
        else:
            length += 1
            s += cur
            a[cur] = 1
    ost = 0
    cur = n // (m * length) * (m * length)
    while cur <= n:
        ost += cur % 10
        cur += m
    print(n // (m * length) * s + ost)

t = int(input())
while (t > 0):
    t -= 1
    n, m = [int(x) for x in input().split()]
    tens = [(m*(i+1)) % 10 for i in range(10)]
    tensum = sum(tens)
    c = n // m
    print(c // 10 * tensum + sum(tens[: c - (c // 10) * 10]))

from sys import stdin
input = stdin.readline

for _ in range(int(input())):
    n, m = [int(i) for i in input().split()]
    
    n //= m
    m %= 10
    
    part_sum = [0 for i in range(10)]
    res = 0
    
    for i in range(1, 10):
        part_sum[i] = (m*i)%10+part_sum[i-1]
        res += (m*i)%10
        
    a, b = (n // 10), (n%10)
    
    
    res *= a
    res += part_sum[b]
    
    print(res)

def mi():
        return list(map(int, input().split()))
'''
7
1 1
10 1
100 3
1024 14
998244353 1337
123 144
1234312817382646 13
1
45
153
294
3359835
0
427262129093995
'''
for _ in range(int(input())):
    n,m= mi()
    lpage = n-n%m
    lmul = lpage//m
    fpage = m
    fmul = 1
    if n<m:
        print(0)
        continue
    c = []
    for i in range(1, 100):
        cons = (i*m)%10
        if not len(c):
            c.append(cons)
        elif c[0]!=cons:
            c.append(cons)
        else:
            break
    nmul = lmul-fmul+1
    # print(c, nmul, nmul//len(c))
    print(sum(c)*(nmul//len(c))+sum(c[:nmul%len(c)]))


MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

t, = I()
while t:
	t -= 1
	n, m = I()
	l = []
	i = 1
	while (i*m)%10 not in l:
		l.append((i*m)%10)
		i += 1
	k = len(l)*m
	ans = sum(l)*(n//k)
	i = n//k * k
	j = 1
	while i + j*m <= n:
		ans += (i+j*m)%10
		j += 1
	print(ans)

#import bisect
#i = bisect.bisect_left(a, k)
#a=[]
#from sys import stdin
#input=stdin.readline
        
for _ in range (int(input())):
    #n=int(input()) 
    ans=0
    n,m=list(map(int, input().split()))
    #a=list(map(int, input().split()))
    a=[]
    if m>n:
        print('0')
        continue
    for i in range(10):
        a.append((m*(i+1))%10)
    s=sum(a)
    
    ans+=((n//(m*10))*s)
    k=n%(10*m)
    p=k//m
    for i in range(p):
        ans+=a[i]
    print(ans)
    #YOUR CODE HERE


t=int(input())
for i in range(t):
    n,m = map(int,input().split())
    a = [0]*11
    for j in range(1,11):
        a[j] = (m*j)%10+a[j-1]
    x = n//m
    print(a[10]*(x//10)+a[x%10])