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 ≤ q ≤ 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 ≤ n, m ≤ 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
import decimal,math
from collections import *
from fractions import gcd
from bisect import bisect_right,bisect_left
import sys

decimal.getcontext().prec = 15

def primeFactors(n): 
	arr=[]
	while n % 2 == 0: 
		arr.append(2) 
		n = n / 2
	for i in xrange(3,int(math.sqrt(n))+1,2): 
		while n % i== 0: 
			arr.append(i) 
			n = n / i 
	if n > 2: 
		arr.append(n)
		# print n
	return arr	 
def z_advanced(s):
	Z = [0] * len(s)
	Z[0] = len(s) 
	rt = 0
	lt = 0
	for k in xrange(1, len(s)):
		if k > rt:
			n = 0
			while n + k < len(s) and s[n] == s[n+k]:
				n += 1
			Z[k] = n
			if n > 0:
				lt = k
				rt = k+n-1
		else:
			p = k - lt  # Pair index.
			right_part_len = rt - k + 1 
			if Z[p] < right_part_len:
				Z[k] = Z[p]
			else:
				i = rt + 1
				while i < len(s) and s[i] == s[i - k]:
					i += 1
				Z[k] = i - k
 
				lt = k
				rt = i - 1
	return max(Z)
def invmod(i,mod):
	return pow(i,mod-2,mod)	
def fact(mod):
	fac= [1,1]
	ifac = [1,1]
	for i in xxrange(2,(3*10**5+ 2)):
		fac.append((fac[-1]*i)%mod)
		# ifac.append((ifac[-1]*invmod(i,mod))%mod)
	return fac,ifac	
def SieveOfEratosthenes(n): 
	prime = [True for i in xrange(n+1)] 
	p = 2
	while (p * p <= n): 
		if (prime[p] == True): 
			
			for i in xrange(p * p, n+1, p): 
				prime[i] = False
		p += 1
	arr=[]
	for p in xrange(2, n): 
		if prime[p]: 
			arr.append(p)
	return arr
def maxSubArraySum(a):
	size=len(a)       
	max_so_far =a[0] 
	curr_max = a[0] 
	for i in xrange(1,size): 
		curr_max = max(a[i], curr_max + a[i]) 
		max_so_far = max(max_so_far,curr_max) 
	return max_so_far 	
def fi():
	return int(sys.stdin.readline())
 
def fi2():
	return map(int, sys.stdin.readline().split())
 
def fi3():
	return sys.stdin.readline()
 
def fo(*args):
	for s in args:
		sys.stdout.write(str(s)+' ')
	sys.stdout.write('\n')
t = int(raw_input())
dp=[]
for i in range(11):
	a=[0]
	for j in range(1,11):
		a.append((i*j)%10+a[-1])
	dp.append(a)	
# print dp	
while(t!=0):
	t=t-1
	n,k=fi2()
	p = n/k
	ans=(p/10)*dp[k%10][10]+dp[k%10][p%10]
	print ans