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: EASY

Solutions:
for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	l = [m % 10]
	for i in range(9):
		l.append((l[-1] + m % 10) % 10)
	a = n // m
	b = a // 10
	ans = b * sum(l)
	for i in range(a % 10):
		ans += l[i]
	print(ans)


def main():
	(a, b) = map(int, input().split())
	dp = [0]
	for i in range(1, 10):
		temp = i * b % 10
		dp.append(temp)
		dp[i] += dp[i - 1]
	div = a // b
	ans = dp[-1] * (div // 10)
	ans += dp[int(a // b % 10)]
	print(ans)
t = int(input())
while t:
	main()
	t -= 1


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	res = [m % 10]
	while True:
		if (res[-1] + m) % 10 == m % 10:
			break
		else:
			res.append((res[-1] + m) % 10)
	S = sum(res) * (n // m // len(res))
	rem = n // m % len(res)
	for i in range(rem):
		S += res[i]
	print(S)


def solve(n, m):
	res = 0
	temp = []
	x = m
	for i in range(1, 11):
		if x > n:
			return sum(temp)
		temp.append(x % 10)
		if n == i:
			return sum(temp)
		x += m
	p = n // m // 10
	res += p * sum(temp)
	rem = n // m % 10
	j = 0
	for i in temp:
		if j == rem:
			break
		res += i
		j += 1
	return int(res)
t = int(input())
for q in range(t):
	(n, m) = map(int, input().split())
	print(solve(n, m))


read = lambda : [int(i) for i in input().split()]
t = int(input())
for _ in range(t):
	(n, m) = read()
	pages = n // m
	cycle_cnt = 1
	cycle_sums = [m % 10]
	k = m * 2
	while k % 10 != m % 10:
		cycle_cnt += 1
		cycle_sums.append(cycle_sums[-1] + k % 10)
		k += m
	ans = cycle_sums[-1] * (pages // cycle_cnt)
	if pages % cycle_cnt != 0:
		ans += cycle_sums[pages % cycle_cnt - 1]
	print(ans)


from pathlib import Path
import sys
import functools
import itertools
import re

def solve():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		cnt = [0] * 10
		tot = n // m
		for c in range(10):
			t = tot // 10
			cnt[c] += t
		for c in range(tot % 10 + 1):
			cnt[c] += 1
		ans = 0
		for c in range(10):
			ans += c * m % 10 * cnt[c]
		print(ans)

def main():
	if Path('test.inp').exists():
		sys.stdin = open('test.inp', 'r')
	solve()
main()


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	e = a // b
	s = 0
	for j in range(1, 10):
		s = s + j * b % 10
	s = s * (e // 10)
	for j in range(1, e % 10 + 1):
		s += j * b % 10
	print(s)


q = int(input())
l = []
for i in range(10):
	l2 = []
	for j in range(10):
		l2.append(int(str((i + 1) * (j + 1))[-1]))
	l.append(l2)
for case in range(q):
	(n, m) = map(int, input().split())
	print(n // m // 10 * sum(l[int(str(m)[-1]) - 1]) + sum(l[int(str(m)[-1]) - 1][:n // m % 10]))


table = {1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 2: [2, 4, 6, 8, 0], 3: [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], 4: [4, 8, 2, 6, 0], 5: [5, 0], 6: [6, 2, 8, 4, 0], 7: [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], 8: [8, 6, 4, 2, 0], 9: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0: [0]}
for test in range(int(input())):
	(n, m) = map(int, input().split(' '))
	lim = n // m
	m = int(str(m)[-1])
	s = 0
	full = lim // len(table[m])
	partial = lim % len(table[m])
	if partial != 0:
		for i in range(partial):
			s += table[m][i]
	s += full * sum(table[m])
	print(s)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = n // m
	u = int(str(m)[-1])
	x = 0
	if u % 2 == 0:
		b = a % 5
		r = a // 5
		x = 5
	elif u % 2 != 0:
		if u == 5:
			b = a % 2
			r = a // 2
			x = 2
		else:
			b = a % 10
			r = a // 10
			x = 10
	t = []
	for j in range(1, x + 1):
		t.append(int(str(u * j)[-1]))
	print(sum(t) * r + sum(t[0:b]))


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
	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())
mod = pow(10, 9) + 7
for y in range(t):
	(n, m) = map(int, input().split())
	u = n // m
	v = m % 10
	c = 0
	if n < m:
		print(0)
	else:
		if v == 0:
			c = 0
		elif m % 2 == 0:
			c = 40 * (u // 10)
		elif v == 5:
			c = 25 * (u // 10)
		else:
			c = 45 * (u // 10)
		for i in range(u % 10):
			c += v * (i + 1) % 10
		print(c)


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


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, deque
from itertools import permutations
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().replace('\n', '').strip()

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(I()):
	(n, m) = tup()
	(ar, k) = ([i * m % 10 for i in range(1, 11)], n // m)
	print(sum(ar) * (k // 10) + sum(ar[:k % 10]))
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print('0')
	elif n == m:
		print(n % 10)
	else:
		arr = []
		tt = 0
		for i in range(1, 11):
			p = m * i
			tt += p % 10
			arr.append(tt)
		e = n // m
		ft = e // 10
		cf = e % 10
		if cf != 0:
			print(ft * arr[9] + arr[cf - 1])
		else:
			print(ft * arr[9])


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		(n, m) = mi()
		f = {}
		a = []
		for i in range(m, n + 1, m):
			x = i % 10
			if x not in f:
				f[x] = 1
				a.append(x)
			else:
				break
		for i in range(1, len(a)):
			a[i] += a[i - 1]
		x = n // m
		if len(a) == 0:
			print(0)
			continue
		x1 = x // len(a)
		x %= len(a)
		print(a[-1] * x1 + (a[x - 1] if x > 0 else 0))
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	m1 = m
	m2 = m1
	s = set()
	while True:
		if int(str(m)[-1]) in s:
			break
		else:
			s.add(int(str(m)[-1]))
			m += m1
	ls = len(s)
	no = n // m2 // ls
	ans = sum(s) * no
	ff = n // m2 % ls
	for i in range(ff):
		ans += int(str(m1)[-1])
		m1 += m2
	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)


q = int(input())
for _ in range(q):
	(n, m) = list(map(int, input().split()))
	l = 0
	a = []
	for i in range(1, 11):
		k = m * i
		l += k % 10
		a.append(k % 10)
	t = n // (m * 10)
	k = t * l
	n = n % (m * 10)
	i = 0
	while m * (i + 1) <= n:
		k += a[i]
		i = i + 1
	print(k)


q = int(input())
out = []
for st in range(0, q):
	[n, m] = [int(x) for x in input().split()]
	if m > n:
		out += [0]
		continue
	iter = m
	sum = 0
	period = []
	while iter <= n:
		tmp = iter % 10
		if tmp in period:
			break
		period += [tmp]
		iter += m
	N = n // m
	No = N // len(period)
	for i in period:
		sum += No * i
	i = 1
	No *= len(period)
	while i + No <= N:
		sum += period[i - 1]
		i += 1
	out += [sum]
for i in range(0, q):
	print(out[i])


l = int(input())
for k in range(l):
	info = [int(a) for a in input().split()]
	iteration = info[0] // (info[1] * 10)
	some = 0
	gulp = 0
	for i in range(10):
		gulp += info[1]
		some += gulp % 10
	otv = iteration * some
	some = 0
	gulp = 0
	for i in range(info[0] % (info[1] * 10) // info[1]):
		gulp += info[1]
		some += gulp % 10
	otv += some
	print(otv)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	i = 0
	while True:
		k = i * m % 10
		if k in l:
			break
		l.append(k)
		i += 1
	z = n // m // len(l)
	z1 = n // m
	ka = z1 * m % 10
	yo = sum(l) * z
	for i in l:
		if i == ka:
			yo += i
			break
		yo += i
	print(yo)


q = int(input())
while q:
	(n, m) = map(int, input().split())
	m = str(m)
	a = m[len(m) - 1]
	m = int(m)
	if a == '0':
		ans = 0
	elif a == '1':
		b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	elif a == '2':
		b = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	elif a == '3':
		b = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	elif a == '4':
		b = [4, 8, 2, 6, 0, 4, 8, 2, 6, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	elif a == '5':
		b = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	elif a == '6':
		b = [6, 2, 8, 4, 0, 6, 2, 8, 4, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	elif a == '7':
		b = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	elif a == '8':
		b = [8, 6, 4, 2, 0, 8, 6, 4, 2, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	else:
		b = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
		ans = n // m // 10 * sum(b)
		c = n // m - n // m // 10 * 10
		d = 0
		while c:
			ans += b[d]
			d += 1
			c -= 1
	print(ans)
	q -= 1


q = int(input())
for j in range(q):
	(n, m) = map(int, input().split())
	numbers = [m % 10]
	cur = 2 * m
	while cur % 10 != m % 10:
		numbers.append(cur % 10)
		cur += m
	s = sum(numbers)
	cnt = n // m
	loops = cnt // len(numbers)
	rest = cnt % len(numbers)
	sumrest = 0
	for i in range(rest):
		sumrest += numbers[i]
	print(loops * s + sumrest)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	cycle = []
	if n < m:
		print(0)
		continue
	if n == m:
		print(n % 10)
		continue
	for i in range(1, 11):
		number = m * i
		last_dif = number % 10
		cycle.append(last_dif)
	no_div = n // m
	complete_cycle = no_div // 10
	in_comp = no_div % 10
	cycle_sum = sum(cycle)
	ans = 0
	if in_comp != 0:
		for i in range(in_comp):
			ans += cycle[i]
	ans += complete_cycle * cycle_sum
	print(ans)


q = int(input())
for _ in range(q):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	count = n // m
	rem = count % 10
	c = (count - rem) // 10
	sum = 0
	if count < 10:
		for i in range(m, n + 1, m):
			last = i % 10
			sum += last
	else:
		for i in range(1, 11):
			last = m * i % 10
			sum += last
		sum = sum * c
		for i in range(1, rem + 1):
			last = m * i % 10
			sum += last
	print(sum)


def cyclic_even(n):
	sumans = 0
	for i in range(1, 6):
		sumans += n * i % 10
	return sumans

def cyclic_odd(n):
	sumans = 0
	for i in range(1, 11):
		sumans += n * i % 10
	return sumans

def custom(n, y):
	sumans = 0
	for i in range(1, y + 1):
		sumans += n * i % 10
	return sumans
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if m % 2 == 0:
		x = n // m // 5
		y = n // m % 5
		ans = x * cyclic_even(m)
		ans += custom(m, y)
		print(ans)
	else:
		x = n // m // 10
		y = n // m % 10
		ans = x * cyclic_odd(m)
		ans += custom(m, y)
		print(ans)


q = int(input())
while q > 0:
	q -= 1
	(n, m) = map(int, input().split())
	firstnum = m
	lastnum = n - n % m
	count = int((lastnum - firstnum) / m) + 1
	pattern = {}
	flag = True
	for i in range(0, n + 1, m):
		if i % 10 not in pattern:
			flag = False
			pattern[i % 10] = 1
		if flag != False:
			break
		flag = True
	sum_ = 0
	pattern_ = list(pattern.keys())
	val = count // len(pattern_)
	extras = count - val * len(pattern_)
	print(sum(pattern_) * val + sum(pattern_[:extras + 1]))


t = int(input())
for ii in range(t):
	(n, m) = [int(x) for x in input().split(' ')]
	d = n // m
	dlist = [int(str(i * m)[-1]) for i in range(1, min(d, 11) + 1)]
	if d < 10:
		print(sum(dlist))
	else:
		x = dlist[0]
		res = x
		end_index = 0
		for (i, a) in enumerate(dlist[1:]):
			if x != a:
				res += a
			else:
				end_index = i + 1
				break
		if end_index:
			cycles = d // end_index
			s = res * cycles
			for i in range(d % end_index):
				s += dlist[i]
			print(s)
		else:
			print(sum(dlist))


def mi():
	return map(int, input().split())
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(sum(c) * (nmul // len(c)) + sum(c[:nmul % len(c)]))


t = int(input())
has = {1: 45, 2: 40, 3: 45, 4: 40, 5: 25, 6: 40, 7: 45, 8: 40, 9: 45}
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	k = n // m
	rec = k % 10
	digit = m % 10
	if digit == 0:
		print(0)
		continue
	k = k // 10
	count = has[digit] * k
	i = 1
	while i <= rec:
		count += digit * i % 10
		i += 1
	print(count)


from sys import stdin
from copy import deepcopy
from collections import deque
q = int(stdin.readline().strip())
for _ in range(q):
	(n, m) = list(map(int, stdin.readline().split()))
	if m > n:
		print(0)
		continue
	s = 0
	for i in range(1, 10):
		s += int(list(str(m * i))[-1])
	count = n // (10 * m)
	s = s * count
	remain = n % (10 * m)
	r = remain // m
	for i in range(1, r + 1):
		s += int(list(str(m * i))[-1])
	print(s)


from collections import defaultdict as dd
t = int(input())
d = dd(list)
for i in range(10):
	d[i] += [0]
	for j in range(1, 10):
		d[i] += [i * j % 10 + d[i][-1]]
for _ in range(t):
	(n, m) = map(int, input().split())
	div = n // m
	last = m % 10
	ans = 0
	ans = div // 10 * d[last][-1] + d[last][div % 10]
	print(ans)


q = int(input())
for t in range(q):
	(n, m) = map(int, input().split())
	cnt = n // m
	vals = []
	for i in range(1, 11):
		if not vals or vals[0] != m * i % 10:
			vals.append(m * i % 10)
		else:
			break
	L = len(vals)
	ans = sum(vals) * (cnt // L)
	cnt %= L
	for i in range(0, cnt):
		ans += vals[i]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	dp = [0] * 12
	l = [m * i % 10 for i in range(1, 11)]
	for i in range(1, 11):
		dp[i] = dp[i - 1] + i * m % 10
	c = n // m
	print(dp[10] * (c // 10) + dp[c % 10])


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

def minp():
	return map(int, input().split())

def iinp():
	return int(input())

def test():
	return int(input())

def inp():
	return input()

def solve():
	(n, m) = map(int, input().split())
	pre = []
	for i in range(1, 11):
		k = m * i
		pre.append(k % 10)
	m = m * 10
	res = sum(pre) * (n // m)
	n = n % m
	res += sum(pre[:n // (m // 10)])
	print(res)

def main():
	for _ in range(test()):
		solve()
main()


t = int(input())
for j in range(t):
	(n, m) = map(int, input().split())
	s = 0
	v = n // m
	m %= 10
	d = m
	o = 0
	for i in range(10):
		o += m
		m += d
		m %= 10
	s += o * (v // 10)
	v %= 10
	for i in range(v):
		s += m
		m += d
		m %= 10
	print(s)


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


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)


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)


Dict = {1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 2: [2, 4, 6, 8, 0], 3: [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], 4: [4, 8, 2, 6, 0], 5: [5, 0], 6: [6, 2, 8, 4, 0], 7: [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], 8: [8, 6, 4, 2, 0], 9: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0: [0]}
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	p = n // m
	Repeatation = p // len(Dict[int(str(m)[-1])])
	Modulo = p % len(Dict[int(str(m)[-1])])
	Ans = Repeatation * sum(Dict[int(str(m)[-1])]) + sum(Dict[int(str(m)[-1])][:Modulo])
	print(Ans)


def main():
	q = int(input())
	for _ in range(q):
		(n, m) = map(int, input().split())
		c = []
		for i in range(10):
			c.append(m * (i + 1) % 10)
		k = n // (m * 10)
		ans = k * sum(c)
		n = n - k * m * 10
		kk = n // m
		ans += sum(c[:kk])
		print(ans)
	return
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	(n, m) = sep()
	s = set()
	ar = []
	f = -1
	for i in range(m, n + m + 1, m):
		if i > n:
			print(sum(ar))
			return
		if i % 10 in s:
			f = i % 10
			break
		ar.append(i % 10)
		s.add(i % 10)
	ind = ar.index(f)
	s1 = sum(ar[:ind])
	temp = sum(ar[ind:])
	cl = len(ar) - ind
	nc = (n // m - ind) // cl
	ans = s1 + nc * temp + sum(ar[:n // m % cl])
	print(ans)
testcase(int(inp()))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	res = 0
	for i in range(1, 11):
		if i * m > n:
			break
		res += i * m % 10
	res = n // (m * 10) * res
	if n % (m * 10) != 0:
		temp = n % (m * 10)
		for i in range(1, 11):
			if i * m > temp:
				break
			res += i * m % 10
	print(res)


import sys
q = int(sys.stdin.readline())
for _ in range(q):
	(n, m) = map(int, sys.stdin.readline().split())
	sum_arr = []
	for i in range(1, 11):
		sum_arr.append(i * m % 10)
	sumVal = sum(sum_arr)
	res = 0
	a = n // m
	b = n // m % 10
	res += sumVal * (a // 10)
	for j in range(b):
		res += sum_arr[j]
	print(res)


from sys import stdin, stdout
from collections import defaultdict
from collections import deque
import math
import copy
T = int(input())
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 * s + sum(tail[:r]))


q = int(input())
for i in range(q):
	(n, m) = list(map(int, input().split()))
	l = []
	l.append(m % 10)
	for i in range(2, 11):
		l.append(l[i - 2] + m * i % 10)
	num = n // m
	ans = num // 10 * l[9]
	rem = num % 10
	if rem != 0:
		ans += l[rem - 1]
	print(ans)


t = int(input())
for j in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	n = L[0]
	m = L[1]
	a = m % 10
	L2 = []
	for i in range(1, 10):
		L2.append(a * i % 10)
	s = sum(L2)
	q = n // m // 10
	som = q * s
	som = som + sum(L2[0:n // m % 10])
	print(som)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	x1 = m % 10
	x2 = x1
	(summa, lst, length) = (0, [], 0)
	while x2 != 0:
		summa += x2
		lst.append(x2)
		length += 1
		x2 += x1
		x2 = x2 % 10
	lst.append(0)
	length += 1
	(div, mod) = (n // (length * m), n % (length * m))
	res = div * summa + sum(lst[:mod // m])
	print(res)


def lastDigit(m):
	return m - 10 * (m // 10)
q = int(input().strip())
for _ in range(q):
	[n, m] = [int(x) for x in input().strip().split(' ')]
	if n < m:
		print('0')
	else:
		lastDigitM = lastDigit(m)
		digits = list()
		for i in range(1, 11):
			if len(digits) == 0:
				digits.append(lastDigit(lastDigitM * i))
			elif digits[0] == lastDigit(lastDigitM * i):
				break
			else:
				digits.append(lastDigit(lastDigitM * i))
		cycleLength = digits.__len__()
		times = n // (m * cycleLength)
		remainder = (n - m * cycleLength * times) // m
		partialSums = [0] * cycleLength
		partialSums[0] = digits[0]
		for i in range(1, cycleLength):
			partialSums[i] = partialSums[i - 1] + digits[i]
		s = times * partialSums[-1]
		if remainder > 0:
			s = s + partialSums[remainder - 1]
		print(s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(ten, one) = (n // m // 10, n // m % 10)
	ans = 0
	val = 0
	for i in range(1, 10):
		val += m * i % 10
		if i == one:
			ans += val
	ans += ten * val
	print(ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split(' '))
	last_digits = []
	num = 0
	while num % 10 not in last_digits:
		last_digits.append(num % 10)
		num += m % 10
	num_digits = len(last_digits)
	sum_last_digits = sum(last_digits)
	num_divisible = n // m
	print(num_divisible // num_digits * sum_last_digits + sum(last_digits[:num_divisible % num_digits + 1]))


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)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	j = a // b
	s = []
	for n in range(1, 11):
		s.append(n * (b % 10) % 10)
	p = j // 10 * sum(s)
	l = j % 10
	for n in range(l):
		p += s[n]
	print(p)


t = int(input())
for k in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	period = 0
	suma = 0
	for i in range(2, 1000):
		suma += b * i % 10
		if i * b % 10 == b % 10:
			period = i - 1
			break
	c = a // b
	ans = suma * (c // period)
	if c % period != 0:
		for i in range(1, c % period + 1):
			ans += b * i % 10
	print(ans)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	u = []
	for i in range(10):
		num = i * m
		if not num in u:
			u.append(num)
	u = [u % 10 for u in u]
	u.remove(0)
	vezes = n // m
	vezesInt = vezes // 10
	vezes = vezes % 10
	total = 0
	total += vezesInt * sum(u)
	total += sum(u[:vezes])
	print(total)


import sys
Input = sys.stdin.readline
n = int(Input())
for i in range(n):
	(n, m) = map(int, Input().split())
	f = 0
	s = 0
	for j in range(0, 10):
		s += m * (j + 1) % 10
	for j in range(0, n // m % 10):
		f += m * (j + 1) % 10
	print(n // m // 10 * s + f)


for tt in range(int(input())):
	(n, m) = map(int, input().split())
	n //= m
	res = 0
	a = []
	for i in range(1, 10):
		a.append(i * m % 10)
	for i in range(n % 10):
		res += a[i]
	r2 = n // 10 * sum(a) + res
	print(r2)


first_place = [[] for i in range(10)]
first_place[0] = [0]
for i in range(1, 10):
	for j in range(0, 10):
		first_place[i].append(i * j % 10)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	multiples = n // m
	(a, b) = divmod(multiples, 10)
	ans = a * sum(first_place[m % 10]) + sum(first_place[m % 10][:b + 1])
	print(ans)


a = []
for i in range(10):
	c = []
	f = 1
	while int(str(i * f)[-1]) not in c:
		c.append(int(str(i * f)[-1]))
		f += 1
	a.append(c)
for i in range(int(input())):
	(s, t) = map(int, input().split())
	p = s // t
	g = int(str(t)[-1])
	print(sum(a[g]) * (p // len(a[g])) + sum(a[g][:p % len(a[g])]))


N = int(input())
nums = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
for _ in range(N):
	(p, m) = map(int, input().split())
	a = m % 10
	num = p // m
	b = num // len(nums[a])
	ans = 0
	for i in nums[a]:
		ans += i * b
	c = num % len(nums[a])
	j = 0
	for i in nums[a]:
		if j == c:
			break
		j += 1
		ans += i
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	sum1 = []
	for i in range(10):
		sum1.append(m * i % 10)
	k = n // m
	val = k // 10 * sum(sum1)
	for i in range(k % 10 + 1):
		val += sum1[i]
	print(val)


import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
T = int(input())
while T > 0:
	(n, m) = get_ints()
	if m % 10 == 0:
		print(0)
		T -= 1
		continue
	elif m % 5 == 0:
		x = 25
	elif m & 1:
		x = 45
	elif not m & 1:
		x = 40
	div = n // m
	tens = div // 10
	total = tens * x
	rem = div % 10
	for i in range(rem):
		total += m * (i + 1) % 10
	print(total)
	T -= 1


for l2 in range(int(input())):
	(n, m) = map(int, input().split())
	a = list()
	(t, s) = (0, 0)
	for j in range(m, 10 * m + 1, m):
		if n < j:
			break
		temp = j % 10
		a.append(temp)
	t = (n - j * (n // j)) // m
	s = sum(a) * (n // j) + sum(a[:t])
	print(s)


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


l = []
for i in range(1, 10):
	k = i
	x = [i]
	m = (i + i) % 10
	while m != 0:
		x.append(m)
		m += i
		m %= 10
	l.append(x)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	x = 0
	if n < m or m % 10 == 0:
		x = 0
	else:
		p = m % 10
		o = n // m
		k = o // (len(l[p - 1]) + 1)
		u = o % (len(l[p - 1]) + 1)
		r = n - o * m
		r = r // p if r != 0 else r
		x = sum(l[p - 1]) * k + sum(l[p - 1][:u])
	print(x)


def main():
	n = int(input())
	for i in range(n):
		(m, n) = [int(v) for v in input().split()]
		div = m // n
		data = []
		for i in range(1, 11):
			data.append(n * i % 10)
		total_sum = sum(data)
		print(div // 10 * total_sum + sum(data[0:div % 10]))
main()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = []
	sum = 0
	ans = 0
	nt = n // m
	if m % 2 == 0:
		for i in range(5):
			arr.append(m * (i + 1) % 10)
			sum += arr[i]
	else:
		for i in range(10):
			arr.append(m * (i + 1) % 10)
			sum += arr[i]
	if m % 2 == 0:
		if nt < 5:
			for i in range(nt):
				ans += arr[i]
		else:
			ans += nt // 5 * sum
			if nt % 5 != 0:
				for i in range(nt % 5):
					ans += arr[i]
	elif nt < 10:
		for i in range(nt):
			ans += arr[i]
	else:
		ans += nt // 10 * sum
		if nt % 10 != 0:
			for i in range(nt % 10):
				ans += arr[i]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	Q = [i * m % 10 for i in range(1, 11)]
	x = n // m
	print(x // 10 * sum(Q) + sum(Q[:x % 10]))


def main():
	(n, m) = [int(i) for i in input().split()]
	ans = 0
	if n < m:
		return 0
	n = n - n % m
	g = n // m
	k = []
	for i in range(1, 10):
		k.append(m * i % 10)
	ans = sum(k) * (g // 10)
	g = g % 10
	if g:
		ans += sum(k[0:g])
	return ans
otv = []
for j in range(int(input())):
	otv.append(main())
print(*otv, sep='\n')


no_of_test_cases = int(input())
for i in range(no_of_test_cases):
	(pages, m) = list(map(int, input().split()))
	if pages < m:
		print(0)
		continue
	multiples = pages // m
	mul = multiples
	ans = 0
	count = 1
	visited = []
	while multiples > 0:
		val = m * count % 10
		if val in visited:
			break
		visited.append(val)
		count += 1
		multiples -= 1
	total = mul // len(visited)
	rem = mul - total * len(visited)
	for i in visited:
		ans += i * total
	for i in range(rem):
		ans += visited[i]
	print(ans)


table = [[0] * 10 for i in range(10)]
for i in range(1, 10):
	for j in range(10):
		table[i][j] = i * j % 10
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	times = n // m
	print(sum(table[m % 10]) * (times // 10) + sum(table[m % 10][:times % 10 + 1]))


def fun():
	(n, m) = input().split()
	(n, m) = [int(n), int(m)]
	x = n // m
	z = x % 10
	arr = []
	arr.append(0)
	s = 0
	for q in range(1, 10):
		o = q * (m % 10) % 10
		arr.append(o)
		s += o
	y = x // 10
	ans = y * s
	for q in range(1, z + 1):
		ans += arr[q]
	print(ans)
t = input()
t = int(t)
i = 0
while i < t:
	fun()
	i += 1


T = int(input())
for i in range(0, T):
	inp = input()
	array_inp = inp.split(' ')
	n = int(array_inp[0])
	m = int(array_inp[1])
	q = n // m
	arr = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
	last_dig = m % 10
	value = q // len(arr[last_dig]) * sum(arr[last_dig])
	for i in range(0, q % len(arr[last_dig])):
		value = value + arr[last_dig][i]
	print(value)


q = int(input())
for _ in range(q):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	times = n // m
	lastDigit = m % 10
	first10Sum = 0
	for i in range(1, 10 + 1):
		first10Sum += i * lastDigit % 10
	loopTimes = times // 10
	remainingTimes = times - 10 * loopTimes
	total = first10Sum * loopTimes
	for i in range(1, remainingTimes + 1):
		total += i * lastDigit % 10
	print(total)


lnums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0, 2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0, 4, 8, 2, 6, 0], [5, 0, 5, 0, 5, 0, 5, 0, 5, 0], [6, 2, 8, 4, 0, 6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0, 8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]

def solve(ninput, lnums):
	total_sum = 0
	(n, m) = (int(ninput[0]), int(ninput[1]))
	last_digit = int(ninput[1][-1]) - 1
	if last_digit == -1 or m > n:
		return total_sum
	repeat = n // m
	(quotient, rem) = divmod(repeat, 10)
	total_sum += quotient * sum(lnums[last_digit])
	total_sum += sum(lnums[last_digit][:rem])
	return total_sum
n = int(input())
for _ in range(n):
	ninput = input().split()
	print(solve(ninput, lnums))


l = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = n // m
	m = m % 10
	k = len(l[m])
	j = s // k + 1
	s = s % k
	print(j * sum(l[m]) - sum(l[m][s:]))


q = int(input())
for i in range(q):
	(n, m) = input().split()
	if int(n) < int(m) or int(m[len(m) - 1]) == 0:
		print(0)
		continue
	arr = [0, 45, 20, 45, 20, 5, 20, 45, 20, 45]
	arr1 = [0, 10, 5, 10, 5, 2, 5, 10, 5, 10]
	ans = 0
	y = int(m[len(m) - 1])
	nomul = int(n) // int(m)
	rem = nomul % 10
	ans = ans + (nomul - rem) // arr1[y] * arr[y]
	x = y
	z = y
	while rem > 0:
		ans += z
		z += y
		z = z % 10
		rem -= 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = 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)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	n //= m
	s = 0
	ans = 0
	for i in range(10):
		s += i * m % 10
		if i == n % 10:
			ans += s
	ans += s * (n // 10)
	print(ans)


qtd = int(input())
for i in range(0, qtd):
	(numerodepaginas, divisor) = list(map(int, input().split()))
	divisao = int(numerodepaginas / (divisor * 10))
	ultimodigito = divisor % 10
	if ultimodigito in [1, 3, 5, 7, 9]:
		numeromagico = 45
	if ultimodigito in [2, 4, 6, 8]:
		numeromagico = 40
	if ultimodigito == 5:
		numeromagico = 25
	if ultimodigito == 0:
		numeromagico = 0
	totalparcial = numeromagico * divisao
	resto = numerodepaginas - divisao * 10 * divisor
	for i in range(divisor, resto + 1, divisor):
		totalparcial += i % 10
	print(totalparcial)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if n < m:
		print(0)
	else:
		arr = []
		for i in range(1, 11):
			m1 = m * i
			mod = m1 % 10
			if mod not in arr:
				arr.append(mod)
		division = n // m
		d = division // len(arr)
		rem = division % len(arr)
		s = sum(arr)
		ans = s * d + sum(arr[0:rem])
		print(ans)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	s = []
	for i in range(10):
		p = m * (i + 1)
		r = str(p)
		q = int(r[-1])
		s.append(q)
	su = sum(s)
	x = n // m
	y = x % 10
	z = x // 10
	print(z * su + sum(s[:y]))


a = int(input())
for i in range(a):
	(n, m) = map(int, input().split())
	k = n // m
	c = 0
	for i in range(10):
		c += m * (i + 1) % 10
	c *= k // 10
	r = 0
	for i in range(k % 10):
		r += m * (i + 1) % 10
	print(c + r)


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


import sys
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print(0)
	else:
		l = []
		i = m
		while i <= 10 * m:
			l.append(i % 10)
			i += m
		for i in range(1, len(l)):
			l[i] = l[i] + l[i - 1]
		x = n // (10 * m)
		c = l[-1] * x
		l.insert(0, 0)
		if n > x * 10 * m:
			c += l[(n - x * 10 * m) // m]
		print(c)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	k = n // m
	l = []
	(c, s) = (0, 0)
	while 1:
		s = s + m
		l.append(s % 10)
		c = c + 1
		if c == 10:
			break
	a = sum(l)
	print(a * (k // 10) + sum(l[0:k % 10]))


dic = {0: [0], 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 2: [2, 4, 6, 8, 0], 3: [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], 4: [4, 8, 2, 6, 0], 5: [5, 0], 6: [6, 2, 8, 4, 0], 7: [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], 8: [8, 6, 4, 2, 0], 9: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]}
l = [sum(dic[i]) for i in range(10)]
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	pages = n // m
	m = str(m)
	last = int(m[-1])
	ans = pages // len(dic[last])
	ans *= l[last]
	ans += sum(dic[last][:pages % len(dic[last])])
	print(ans)


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]))


R = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, m) = R()
	if n < m:
		print(0)
		continue
	L = []
	p = m
	for i in range(10):
		k = p % 10
		if k in L:
			break
		L.append(k)
		p = m * (i + 2)
	l = len(L)
	s = sum(L)
	res = n // (l * m) * s
	res += sum(L[:n % (l * m) // m])
	print(res)


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


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	sums = 0
	rems = 0
	div = n // m
	if div != 0:
		div_ = div // 10
		for i in range(m, m * 9 + 1, m):
			sums += i % 10
		count = div % 10
		i = m
		while count:
			count -= 1
			rems += i % 10
			i = i + m
		sums = sums * div_ + rems
		print(sums)
	else:
		print(0)


import math
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	if m % 10 == 0:
		print(0)
	else:
		period = 1
		sum = 0
		while period * m % 10 != 0:
			sum += period * m % 10
			period += 1
		period_len = period * m
		n_period = math.floor(n / period_len)
		remain = n - n_period * period_len
		sum2 = 0
		if m <= n:
			for j in range(n - remain, n + 1, m):
				sum2 += j % 10
		print(n_period * sum + sum2)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	x = m % 10
	c = n // m
	z = 0
	if x == 0:
		print(0)
	elif x == 1:
		v = c // 10
		v = v * 45
		y = c % 10
		f = x
		for i in range(1, y + 1):
			z = z + f % 10
			f = f + x
		print(v + z)
	elif x == 2:
		v = c // 5
		v = v * 20
		y = c % 5
		f = x
		for i in range(1, y + 1):
			z = z + f % 10
			f = f + x
		print(v + z)
	elif x == 3:
		v = c // 10
		v = v * 45
		y = c % 10
		f = x
		for i in range(1, y + 1):
			z = z + f % 10
			f = f + x
		print(v + z)
	elif x == 4:
		v = c // 5
		v = v * 20
		y = c % 5
		f = x
		for i in range(1, y + 1):
			z = z + f % 10
			f = f + x
		print(v + z)
	elif x == 5:
		v = c // 2
		v = v * 5
		if c % 2 != 0:
			v = v + 5
		print(v)
	elif x == 6:
		v = c // 5
		v = v * 20
		y = c % 5
		f = x
		for i in range(1, y + 1):
			z = z + f % 10
			f = f + x
		print(v + z)
	elif x == 7:
		v = c // 10
		v = v * 45
		y = c % 10
		f = x
		for i in range(1, y + 1):
			z = z + f % 10
			f = f + x
		print(v + z)
	elif x == 8:
		v = c // 5
		v = v * 20
		y = c % 5
		f = x
		for i in range(1, y + 1):
			z = z + f % 10
			f = f + x
		print(v + z)
	else:
		v = c // 10
		v = v * 45
		y = c % 10
		f = x
		for i in range(1, y + 1):
			z = z + f % 10
			f = f + x
		print(v + z)


def sum_digits(n, m):
	(temp, lst) = (m % 10, [0] * 10)
	lst[0] = 0
	for i in range(1, 10):
		lst[i] = lst[i - 1] + temp * i % 10
	return lst[-1] * (n // (m * 10)) + lst[n // m % 10]
t = int(input())
for j in range(t):
	(N, M) = [int(x) for x in input().split()]
	print(sum_digits(N, M))


q = int(input())
for _ in range(q):
	(n, m) = [int(x) for x in input().split()]
	s = set()
	intt = []
	i = 1
	while True:
		temp = int(str(i * m)[-1])
		if temp in s:
			break
		else:
			s.add(temp)
			intt.append(temp)
			i += 1
	c = n // m
	temp1 = c // len(intt)
	temp2 = c % len(intt)
	res = 0
	for i in range(temp2):
		res += intt[i]
	print(res + temp1 * sum(intt))


number = int(input())
for i in range(number):
	tem = input()
	data = tem.split()
	page = int(data[0])
	div = int(data[1])
	div_list = [div % 10]
	tem = div % 10
	while True:
		tem = (tem + div % 10) % 10
		if tem != div_list[0]:
			div_list.append(tem)
		else:
			break
	no = len(div_list)
	total = 0
	for i in div_list:
		total += i
	loop = page // div // no
	rem = page // div % no
	tem_total = 0
	for i in range(rem):
		tem_total += div_list[i]
	print(tem_total + loop * total)


def f(n, m):
	if n < m:
		a = 0
	else:
		x = 0
		l = []
		for i in range(1, 10):
			l.append(m * i % 10)
			x = x + m * i % 10
		l.append(0)
		b = n // m
		c = b // 10
		a = c * x
		d = b - c * 10
		for i in range(0, d):
			a = a + l[i]
	return a
q = int(input())
for i in range(0, q):
	(n, m) = map(int, input().split())
	print(f(n, m))


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	if m % 10 == 0:
		(x, y) = (1, 0)
	elif m % 2 == 0:
		(x, y) = (5, 20)
	elif m % 5 == 0:
		(x, y) = (2, 5)
	else:
		(x, y) = (10, 45)
	c = n // m
	ans = c // x * y
	if c > 0:
		d = c % x
		for i in range(d):
			ans += m * (i + 1) % 10
	print(ans)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	(n, m) = inm()
	first = []
	for i in range(1, 11):
		first.append(int(str(m * i)[-1]))
	ans = 0
	if n >= m * 10:
		ans += n // (m * 10) * sum(first) + sum(first[:n % (m * 10) // m])
	elif n >= m:
		ans += sum(first[:n // m])
	print(ans)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	c = []
	ans = 0
	for i in range(m, n + 1, m):
		cur = i % 10
		if cur not in c:
			c.append(cur)
		else:
			break
	p = n // m
	if len(c) != 0:
		ans = sum(c) * (p // len(c))
		r = p % len(c)
		for i in range(r):
			ans += c[i]
	print(ans)


arr = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 45], [2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 40], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0, 45], [4, 8, 2, 6, 0, 4, 8, 2, 6, 0, 40], [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 25], [6, 2, 8, 4, 0, 6, 2, 8, 4, 0, 40], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0, 45], [8, 6, 4, 2, 0, 8, 6, 4, 2, 0, 40], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 45]]

def func(q, lastDigit):
	sum = 0
	for i in range(q % 10):
		sum += arr[lastDigit][i]
	sum += arr[lastDigit][10] * (q // 10)
	print(sum)
	return
testCase = int(input())
for i in range(testCase):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	lastDigit = m % 10
	func(n // m, lastDigit)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

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

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] >= arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def solve():
	(n, m) = num_input()
	if m % 10 == 0:
		print(0)
		return
	n = n // m * m
	if n == 0:
		print(0)
		return
	ans = 0
	if m % 2 == 0:
		upper = n // (m * 10)
		if upper == 0:
			c = 1
			while m * c <= n:
				ans += m * c % 10
				c += 1
		else:
			ans = 40 * upper
			c = n // (m * 10) * (m * 10) // m + 1
			while m * c <= n:
				ans += m * c % 10
				c += 1
	elif m % 5 == 0:
		upper = n // m
		ans = 5 * (upper // 2)
		if upper % 2 != 0:
			ans += 5
	else:
		upper = n // (m * 10)
		if upper == 0:
			c = 1
			while m * c <= n:
				ans += m * c % 10
				c += 1
		else:
			ans = 45 * upper
			c = n // (m * 10) * (m * 10) // m + 1
			while m * c <= n:
				ans += m * c % 10
				c += 1
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


q = int(input())
for w in range(q):
	(n, m) = map(int, input().split())
	k = n // m
	if k == 0:
		print(0)
	else:
		divisors = []
		for i in range(m, n + 1, m):
			if i % 10 in divisors:
				break
			divisors.append(i % 10)
		s = sum(divisors) * (k // len(divisors))
		s += sum(divisors[:k % len(divisors)])
		print(s)


q = int(input())
answer = []
for _ in range(q):
	(n, m) = map(int, input().split())
	s = 0
	ans = 0
	q = m % 10
	for i in range(1, q * 10 + 1):
		if i % q == 0:
			s += i % 10
	ans += s * (n // (m * 10))
	n -= n // (m * 10) * (m * 10)
	n //= m
	for i in range(1, q * n + 1):
		if i % q == 0:
			ans += i % 10
	answer.append(ans)
print(*answer, sep='\n')


import math
alph = 'abcdefghijklmnopqrstuvwxyz'
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	a = []
	k = m % 10
	for j in range(1, 11):
		if a.count(k * j % 10) == 0:
			a.append(k * j % 10)
		else:
			break
	print(n // m // len(a) * sum(a) + sum(a[0:n // m % len(a)]))


from bisect import insort, bisect_left
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
	q = int(input())
	for k in range(q):
		(n, m) = map(int, input().split())
		c = 0
		loop = 0
		l = []
		ans = 0
		for i in range(1, 11):
			a = int(str(i * m)[-1])
			if a == 0:
				loop = i
				break
			l.append(a)
			c += a
		t = n - n % m
		for i in range(n // m % loop):
			ans += l[i]
		print(ans + c * (n // m // loop))
main()


N = int(input())
for i in range(N):
	summary = 0
	sum_cycle = 0
	tmp = input().split()
	tmp = list(map(int, tmp))
	n = tmp[0]
	m = tmp[1]
	mas = []
	cycle = 0
	if m <= n:
		for j in range(10):
			sum_cycle = sum_cycle + m
			cycle += sum_cycle % 10
		summary += cycle * (n // sum_cycle)
		j = 0
		while j <= n % sum_cycle:
			summary += j % 10
			j = j + m
	print(summary)


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)


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)


I0 = lambda : map(int, input().split())
I1 = lambda : int(input())
I2 = lambda : list(map(int, input().split()))

def cal(j, t, n, m1):
	yy = t * m1
	x = (n - j) // yy
	return x
for i in range(I1()):
	(n, m) = I0()
	res = 0
	num = [0] * 10
	m1 = m
	b = list()
	tol = 0
	while m <= n:
		if num[m % 10] == 0:
			num[m % 10] = 1
			b.append(m)
			tol += 1
			m += m1
		else:
			break
	for j in b:
		num[j % 10] += cal(j, tol, n, m1)
	for j in range(10):
		res += num[j] * j
	print(res)


for _ in range(int(input())):
	(n, m) = (int(s) for s in input().split())
	su = 0
	w = m % 10
	l = [w * i % 10 for i in range(10)]
	s = {}
	for i in range(10):
		s[l[i]] = 0
	w1 = 9
	for i in range(10):
		s[l[i]] += 1
		if s[l[i]] == 2:
			w1 = i - 1
			break
	l = l[:w1 + 1]
	k1 = n // m
	su += sum(l) * (k1 // len(l))
	su += sum(l[:k1 % len(l) + 1])
	print(su)


import sys, math
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

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

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	(n, m) = getVars()
	k = n // m
	m = m % 10
	res = 0
	for i in range(1, 10):
		res += m * i % 10
	res *= k // 10
	for i in range(1, k - k // 10 * 10 + 1):
		res += m * i % 10
	print(res)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = []
	for i in range(1, 10):
		arr.append(k * i % 10)
	ff = n // k
	ans = ff // 10 * sum(arr) + sum(arr[:ff % 10])
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(1, 11):
		arr.append(i * m % 10)
	s = sum(arr)
	f = n // m
	ans = 0
	ans += f // 10 * s
	ans += sum(arr[:f % 10])
	print(ans)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	per = [m % 10]
	per_sum = m % 10
	k = 2 * m
	kol1 = 1
	while m % 10 != k % 10:
		per.append(k % 10)
		kol1 += 1
		per_sum += k % 10
		k += m
	kol = n // m
	sum1 = 0
	sum1 += kol // kol1 * per_sum
	kol -= kol // kol1 * kol1
	for i in range(kol):
		sum1 += per[i]
	print(sum1)


queries = int(input())
for q in range(queries):
	splits = input().split(' ')
	n = int(splits[0])
	m = int(splits[1])
	m_last_digit = m % 10
	last_digits = []
	for i in range(1, 10):
		last_digits.append(m_last_digit * i % 10)
	groups = n // (10 * m)
	residual = n // m % 10
	result = groups * sum(last_digits) + sum(last_digits[:residual])
	print(result)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	counts = n // m
	last = [i * m % 10 for i in range(10)]
	total = sum(last) * (counts // 10) + sum(last[:counts % 10 + 1])
	print(total)


for _ in range(int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	c = 0
	s = 0
	for i in range(1, 10):
		s += m * i % 10
	a = n // m
	b = a // 10
	c += b * s
	d = a % 10
	for i in range(1, d + 1):
		c += m * i % 10
	print(c)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	(c, m, d) = (n // m, m % 10, [])
	i = m
	while True:
		if not i in d:
			d.append(i)
			i += m
			i %= 10
		else:
			break
	ans = c // len(d)
	c -= ans * len(d)
	ans *= sum(d)
	if c > 0 and c <= n:
		ans += sum(d[:c])
	print(ans)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	sum = 0
	if n <= m * 10:
		for i in range(m, n + 1, m):
			sum += i % 10
		print(sum)
	else:
		for i in range(m, m * 10 + 1, m):
			sum += i % 10
		a = n // (m * 10)
		sum *= a
		if n % (m * 10) != 0:
			for i in range(m * 10 * a, n + 1, m):
				sum += i % 10
		print(sum)


for _ in range(int(input())):
	ans = 0
	(n, m) = 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)


for i in range(int(input())):
	(n, m) = [int(k) for k in input().split(' ')]
	not_complete = True
	list_of_endings = []
	i = 1
	while not_complete:
		if i * m % 10 in list_of_endings:
			not_complete = False
		else:
			list_of_endings.append(i * m % 10)
			i += 1
	t = n // m
	tt = t // len(list_of_endings)
	rest = t % len(list_of_endings)
	print(sum(list_of_endings) * tt + sum(list_of_endings[:rest]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = n // m
	start = m % 10
	cnt = 0
	i = 2
	sum = start
	result = 0
	while True:
		if m * i % 10 == start:
			break
		sum = sum + m * i % 10
		i += 1
	i -= 1
	result = sum * (c // i)
	c = c % i
	for x in range(1, c + 1):
		result += m * x % 10
	print(result)


import math
q = int(input())
for _ in range(q):
	(n, m) = [int(x) for x in input().split()]
	last = []
	i = k = m % 10
	while i % 10 != 0:
		last.append(i % 10)
		i += k
	last += [0]
	s = sum(last)
	times = 0
	ans = end = 0
	if n >= len(last) * m:
		end = m * len(last)
		times = n // end
		ans = s * times
	for i in range(0, (n - end * times) // m):
		ans += last[i]
	print(ans)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	k = n // m
	use = k // 10
	rem = k % 10
	store = 0
	for it in range(10):
		store += (it + 1) * m % 10
	ans = use * store
	for i in range(rem):
		ans += (i + 1) * m % 10
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	x = m % 10
	s = []
	for j in range(1, 10):
		z = x * j
		s.append(z % 10)
	k = sum(s)
	z = n // (m * 10)
	ans = k * z
	z = n - z * (m * 10)
	z = z // m
	for j in range(1, z + 1):
		ans = ans + j * x % 10
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	e = []
	r = m % 10
	for i in range(1, 10 + 1):
		q = 1
		for j in e:
			if i * r % 10 == j:
				q = 0
		if q:
			e.append(i * r % 10)
	s = sum((i for i in e))
	ss = 0
	for i in range(0, n // m % len(e)):
		ss += e[i]
	ss += s * (n // m // len(e))
	print(ss)


def problem():
	(num_pages, divisor) = map(int, input().split(' '))
	seen = set()
	for i in range(0, num_pages + 1, divisor):
		candidate = i % 10
		if candidate in seen:
			break
		seen.add(candidate)
	cycle_length = len(seen)
	cycle_value = sum(seen)
	num_written_pages = num_pages // divisor
	num_cycles = num_written_pages // cycle_length
	partial_sum = cycle_value * num_cycles
	remainder_position = num_cycles * cycle_length * divisor
	for i in range(remainder_position, num_pages + 1, divisor):
		partial_sum += i % 10
	print(partial_sum)
n = int(input())
for i in range(n):
	problem()


from math import floor
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	p = n // m
	sum = 0
	for i in range(10):
		sum += m * (i + 1) % 10
	sum *= p // 10
	for i in range(p % 10):
		sum += m * (i + 1) % 10
	print(sum)


q = int(input())
for iter1 in range(q):
	(n, m) = map(int, input().split())
	remainder = []
	for i in range(m, 10 * m + 1, m):
		remainder.append(i % 10)
	ans = sum(remainder) * ((n - m) // (10 * m))
	for i in range((n - m) // (10 * m) * (10 * m), n + 1, m):
		ans += i % 10
	print(ans)


Q = int(input())
for q in range(Q):
	a = 0
	(n, m) = map(int, input().split())
	t1 = n // m
	if m % 10 == 0:
		print(0)
	elif m % 2 == 0:
		t2 = t1 // 5 * 20
		t3 = t1 % 5
		for i in range(1, t3 + 1):
			t2 = t2 + i * (m % 10) % 10
		print(t2)
	elif m % 5 == 0:
		t2 = t1 // 2 * 5
		t3 = t1 % 2
		if t3 == 1:
			t2 = t2 + 5
		print(t2)
	else:
		t2 = t1 // 10 * 45
		t3 = t1 % 10
		for i in range(1, t3 + 1):
			t2 = t2 + i * (m % 10) % 10
		print(t2)


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]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	k = m % 10
	e = 0
	t = m
	p = []
	while k not in p:
		p.append(k)
		t = t + m
		e = e + k
		k = t % 10
	r = n // m
	c = r // len(p)
	rem = r % len(p)
	ans = c * e + sum(p[0:rem])
	print(ans)


import sys
import copy
sys.setrecursionlimit(1000000)
Q = int(input())
for _ in range(Q):
	(n, m) = map(int, input().split())
	times = n // m
	first = m % 10
	a = [(i + 1) * m % 10 for i in range(10)]
	ans = sum(a) * (times // 10)
	for i in range(times % 10):
		ans += a[i]
	print(ans)


T = int(input().strip())
while T > 0:
	T -= 1
	(a, b) = map(int, input().strip().split())
	x = a // b
	sum = 0
	s1 = 0
	for i in range(1, 10):
		s1 += i * b % 10
	for i in range(1, x % 10 + 1):
		sum += i * b % 10
	sum += x // 10 * s1
	print(sum)


def period(x):
	y = x % 10
	(k, s) = (1, y)
	while True:
		x = (x + y) % 10
		if x == y:
			break
		k += 1
		s += x
	return (k, s)

def calc(n, m):
	t = n // m
	(k, s) = period(m)
	ans = t // k * s
	x = m % 10
	for i in range(t % k):
		ans += x
		x = (x + m % 10) % 10
	return ans
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	print(calc(n, m))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	k = n // m
	v = 0
	for i in range(1, 11):
		v += m * i % 10
	ans1 = k // 10 * v
	ans2 = 0
	for j in range(1, k % 10 + 1):
		ans2 += m * j % 10
	print(ans1 + ans2)


for i in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	l = []
	k = n // m
	for j in range(1, 11):
		v = m * j
		l.append(int(str(v)[-1]))
	print(sum(l) * (k // 10) + sum(l[:k % 10]))


for i in range(int(input())):
	(n, m) = (int(j) for j in input().split())
	s = 0
	if m <= n:
		z = 0
		nums = []
		while z <= n:
			if z % 10 in nums:
				s += sum(nums) * (n // z)
				z = z * (n // z)
				break
			else:
				nums.append(z % 10)
			if z + m > n:
				s += sum(nums) * (n // z)
				z = z * (n // z)
				break
			z += m
		while z + m <= n:
			z += m
			s += z % 10
	print(s)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	last_digit = m % 10
	cycles = n // m
	value_cycle = {2: (5, 20), 3: (10, 45), 4: (5, 20), 5: (2, 5), 6: (5, 20), 7: (10, 45), 8: (5, 20), 9: (10, 45), 0: (1, 0), 1: (10, 45)}
	val = value_cycle[last_digit]
	quo = cycles // val[0]
	rest = cycles % val[0]
	r = 0
	su = 0
	for j in range(rest):
		su += m
		r += su % 10
	print(quo * val[1] + r)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	f = m % 10
	c = []
	i = 1
	while f * i % 10 not in c:
		c.append(f * i % 10)
		i += 1
	res = n // m % len(c)
	ans = n // m // len(c) * sum(c) + sum(c[:res])
	print(ans)


q = int(input())
for _ in range(q):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	s = set([])
	e = b
	while e % 10 not in s:
		s.add(e % 10)
		e += b
	ans = a // b // len(s) * sum(s)
	e = b
	for _ in range(a // b % len(s)):
		ans += e % 10
		e += b
	print(ans)


q = int(input())
for i in range(q):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	lm = m % 10
	d = n // m
	ans = 0
	dt = d - d % 10
	p = [0, 45, 40, 45, 40, 25, 40, 45, 40, 45]
	ans = ans + p[lm] * (dt // 10)
	for k in range(0, d % 10 + 1):
		ans = ans + m * k % 10
	print(int(ans // 1))


q = int(input())
mapper = dict()
for i in range(10):
	(temp, temp_val) = (list(), 0)
	for j in range(10):
		temp_val += i * j % 10
		temp.append(temp_val)
	mapper[i] = temp
while q > 0:
	(n, m) = map(int, input().split())
	quo = n // m
	rem = quo % 10
	ans = quo // 10 * mapper[m % 10][9] + mapper[m % 10][rem]
	print(ans)
	q -= 1


t = int(input())
for _ in range(t):
	(m, n) = list(map(int, input().split(' ')))
	l = []
	for i in range(1, 11):
		if i * n % 10 not in l:
			l.append(i * n % 10)
		else:
			break
	cnt = len(l)
	p = m // n
	print(p // cnt * sum(l) + sum(l[:p % cnt]))


import sys
input = sys.stdin.readline
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for (N, M) in Query:
	used = set()
	loop = []
	c = 0
	while True:
		c = (c + M) % 10
		if c in used:
			break
		loop.append(c)
		used.add(c)
	times = N // M
	L = len(loop)
	ans = sum(loop) * (times // L) + sum(loop[:times % L])
	print(ans)


import math
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	a = [m % 10]
	for i in range(2, 10):
		a.append(m * i % 10)
	sum_of_10 = sum(a)
	temp = int((n - n % m) / m)
	print(int(temp / 10) * sum_of_10 + sum(a[0:temp % 10]))


from math import *
t = input()
for i in range(0, int(t)):
	(n, m) = map(int, input().split())
	s = 0
	a = n // m
	x = a // 10
	y = a % 10 + 1
	for j in range(1, 10):
		q = m * j % 10
		s = s + q
	s = s * x
	for u in range(1, y):
		r = m * u % 10
		s = s + r
	print(s)


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	have = [i * k % 10 for i in range(1, 11)]
	ans = sum(have) * (n // (k * 10))
	n = n % (k * 10)
	ans += sum(have[:n // k])
	print(ans)


for _ in range(int(input())):
	s = 0
	y = 0
	(n, m) = list(map(int, input().split()))
	if m > n:
		print(0)
	else:
		number = str(n // m)
		last = int(number[-1])
		for i in range(1, 11):
			t = str(i * m)
			s += int(t[-1])
			if last == i:
				y = s
		ans = (int(number) - last) * s // 10 + y
		print(ans)


def bookReading(n, m):
	summ = 0
	if m * 10 < n:
		for i in range(m, m * 10 + 1, m):
			summ += i % 10
		summ = summ * (n // (m * 10))
		rem = n % (m * 10)
		for i in range(m, rem + 1, m):
			summ += i % 10
	else:
		for i in range(m, n + 1, m):
			summ += i % 10
	return summ
t = int(input())
for i in range(t):
	arr = list(map(int, input().split()))
	print(bookReading(arr[0], arr[1]))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	n1 = n // m
	m1 = m % 10
	d = []
	for j in range(1, 11):
		a = m1 * j
		d.append(a % 10)
	n2 = n1 // 10
	s = n2 * sum(d)
	n3 = n1 % 10
	s += sum(d[0:n3])
	print(s)


a = []
for i in range(10):
	b = [i]
	last = i * 2 % 10
	while last != i:
		b.append(last)
		last = (last + i) % 10
	a.append(b)
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	last = m % 10
	ans = 0
	ans += n // m // len(a[last]) * sum(a[last])
	m = n // m % len(a[last])
	ans += sum(a[last][:m])
	print(ans)


def genRepeat(x):
	arr = [i * (x % 10) % 10 for i in range(1, 11)]
	return (sum(arr), arr)
memo = {i: genRepeat(i) for i in range(0, 10)}
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = n // m
	(a, b) = (a // 10, a % 10)
	tp = memo[m % 10]
	res = a * tp[0] + sum(tp[1][:b])
	print(res)


q = int(input())
while q > 0:
	(n, m) = [int(x) for x in input().split()]
	sum = 0
	quotient = n // m // 10
	remainder = n // m % 10
	for i in range(1, 10, 1):
		sum += m * i % 10 * (quotient + (1 if remainder >= i else 0))
	print(sum)
	q -= 1


q = int(input())
for i in range(0, q):
	(n, m) = map(int, input().split())
	k = n // m
	cycle = [0 for i in range(10)]
	for i in range(0, 10):
		cycle[i] = (i + 1) * m % 10
	ans = 0
	for i in range(0, k % 10):
		ans += cycle[i]
	print(ans + k // 10 * sum(cycle))


a1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
a2 = [2, 4, 6, 8, 0]
a3 = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
a4 = [4, 8, 2, 6, 0]
a5 = [5, 0]
a6 = [6, 2, 8, 4, 0]
a7 = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
a8 = [8, 6, 4, 2, 0]
a9 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
a = [a1, a2, a3, a4, a5, a6, a7, a8, a9]
t = int(input())

def solve(n, m):
	count = 0
	if n % 10 == 0:
		return 0
	count += compute(n, m, n % 10)
	n //= 10
	return count

def compute(n, m, o):
	p = m // n
	q = p // len(a[o - 1])
	r = p % len(a[o - 1])
	d = q * sum(a[o - 1]) + sum(a[o - 1][:r])
	return d
while t > 0:
	t -= 1
	(m, n) = input().split()
	n = int(n)
	m = int(m)
	print(solve(n, m))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	x = m % 10
	arr = [x]
	a = m + m
	while a % 10 != x:
		arr.append(a % 10)
		a += m
	summ = sum(arr)
	full = n // m // len(arr) * summ
	rem = n // m % len(arr)
	for i in range(0, rem):
		full += arr[i]
	print(full)


lastDigits = [[0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8], [0, 3, 6, 9, 2, 5, 8, 1, 4, 7], [0, 4, 8, 2, 6], [0, 5], [0, 6, 2, 8, 4], [0, 7, 4, 1, 8, 5, 2, 9, 6, 3], [0, 8, 6, 4, 2], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]]
for _ in range(int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	total = 0
	i = n // m
	l = len(lastDigits[m % 10])
	(q, r) = (i // l, i % l)
	print(q * sum(lastDigits[m % 10]) + sum(lastDigits[m % 10][:r + 1]))


n = int(input())
for i in range(n):
	(n, m) = map(int, input().split())
	(temp, temp1, temp2) = (0, 0, 0)
	k = n // m
	temp = k // 10
	for i in range(9):
		temp1 += m * (i + 1) % 10
	for i in range(k % 10):
		temp2 += m * (i + 1) % 10
	print(temp * temp1 + temp2)


import sys

def main():

	def input():
		return sys.stdin.readline()[:-1]
	q = int(input())
	for k in range(q):
		(m, n) = map(int, input().split())
		s = []
		for l in range(1, 11):
			s.append(l * n % 10)
		t = sum(s)
		print(t * (m // n // 10) + sum(s[:m // n % 10]))
main()


d = {}
d[1] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
d[2] = [2, 4, 6, 8, 0]
d[3] = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
d[4] = [4, 8, 2, 6, 0]
d[5] = [5, 0]
d[6] = [6, 2, 8, 4, 0]
d[7] = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
d[8] = [8, 6, 4, 2, 0]
d[9] = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
d[0] = [0]
b = [0, 45, 20, 45, 20, 5, 20, 45, 20, 45]
c = [1, 10, 5, 10, 5, 2, 5, 10, 5, 10]
a = int(input())
for i in range(a):
	(n, m) = map(int, input().split())
	mm = m % 10
	nn = n // m
	s = nn // c[mm] * b[mm]
	for i in range(nn % c[mm]):
		s += d[mm][i]
	print(s)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().rstrip().split(' '))
	first_10_with_m = [m * i % 10 for i in range(1, 10)]
	s = sum(first_10_with_m)
	number_of_cycles = n // (m * 10)
	total = number_of_cycles * s
	z = n % (m * 10) // m
	if z:
		total = total + sum(first_10_with_m[:z])
	print(total)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	k = n // m
	liczby = [0 for _ in range(10)]
	for i in range(10):
		liczby[i] = (i + 1) * m % 10
	suma = 0
	for i in range(k % 10):
		suma += liczby[i]
	print(k // 10 * sum(liczby) + suma)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	d = {}
	for i in range(m, m * 10 + 1, m):
		d[i] = i % 10
	sm = 0
	if n <= m * 10:
		for i in range(m, n + 1, m):
			sm += d[i]
		ans = sm
	else:
		for i in range(m, m * 10 + 1, m):
			sm += d[i]
		res = n // (m * 10)
		ans = res * sm
		for i in range(m * 10 * res + m, n + 1, m):
			ans += i % 10
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(1, 11):
		l.append(m * i % 10)
	ans = sum(l) * (n // (m * 10))
	p = n % (m * 10)
	for i in range(1, 10):
		if m * i <= p:
			ans += m * i % 10
		else:
			break
	print(ans)


import math

def BookReading(l):
	n_ = l[0]
	m_ = l[1]
	sum_ = 0
	curr_n = m_
	multiples = 0
	i = 1
	while i < 10:
		multiples += m_
		sum_ += multiples % 10
		i += 1
	without_r = sum_ * math.floor(n_ / m_ / i)
	r = n_ // m_ % i
	sum_ = 0
	multiples = 0
	for j in range(0, r):
		multiples += m_
		sum_ += multiples % 10
	with_r = sum_
	if r == 0:
		with_r = 0
	print(without_r + with_r)
n = int(input())
for i in range(0, n):
	BookReading(list(map(int, input().rstrip().split())))


for q in range(int(input())):
	(n, m) = map(int, input().split())
	if n < 10 * m:
		cnt = 0
		i = 1
		while i * m <= n:
			cnt += int(str(i * m)[-1])
			i += 1
		print(cnt)
		continue
	a = [i * m % 10 for i in range(1, 12)]
	i = 1
	while a[i] != a[0]:
		i += 1
	n //= m
	s = sum(a[:i])
	r = n % i
	print(s * (n // i) + sum(a[:r]))


for ttt in range(int(input())):
	(n, m) = map(int, input().split())
	k = n // m
	kk = k // 10
	ans = 0
	for i in range(10):
		ans += kk * (m * (i + 1) % 10)
	for i in range(k % 10):
		ans += m * (i + 1) % 10
	print(ans)


arr = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0, 2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0, 4, 8, 2, 6, 0], [5, 0, 5, 0, 5, 0, 5, 0, 5, 0], [6, 2, 8, 4, 0, 6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0, 8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
q = int(input())
for _ in range(q):
	(n, m) = list(map(int, input().split()))
	last = m % 10
	s = 0
	for i in range(10):
		s += arr[last][i]
	times = n // m // 10
	total = times * s
	mod = n // m % 10
	for i in range(mod):
		total += arr[last][i]
	print(total)


Q = int(input())
for q in range(Q):
	(n, m) = tuple(map(int, input().split()))
	i = m
	ends = set()
	s = 0
	for i in range(m, m * 11, m):
		end = i % 10
		if end in ends:
			break
		else:
			ends.add(end)
			s += end
	count = n // m
	ans = count // len(ends) * s
	count %= len(ends)
	for i in range(m, m * count + 1, m):
		ans += i % 10
	print(ans)


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
for i in range(int(input())):
	(n, m) = map(int, input().split())
	s = 0
	for i in range(11):
		s += int(str(i * m)[-1])
	s1 = i * m
	ans = 0
	if n > m:
		ans += n // s1 * s
	elif n < m:
		print(0)
		continue
	for i in range(s1 * (n // s1), n + 1, m):
		if i % m == 0:
			ans += int(str(i)[-1])
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print(0)
		continue
	if n == m:
		print(n % 10)
		continue
	a = []
	b = []
	for i in range(1, 11):
		if i * m > n:
			break
		a.append(i * m % 10)
		b.append(i * m)
	su = sum(a)
	nq = n // b[len(b) - 1]
	su = su * nq
	s = n - nq * b[len(b) - 1]
	for i in range(len(b)):
		if b[i] <= s:
			su += b[i] % 10
	print(su)


def other(n, m):
	k = n // m
	cycle = lambda i: m * (i + 1) % 10
	sum1 = k // 10 * sum([cycle(i) for i in range(10)]) + sum([cycle(i) for i in range(k % 10)])
	return sum1
q = int(input())
for i in range(q):
	(n, m) = [int(i) for i in input().split()]
	print(other(n, m))


q = int(input())
for _ in range(q):
	(m, n) = map(int, input().split())
	k = m // (10 * n)
	res = 0
	result = 0
	j = 0
	p = 0
	if k >= 1:
		for i in range(1, 11):
			res += p % 10
			p += n % 10
	os = m - k * 10 * n
	while j <= os:
		result += j % 10
		j += n
	print(result + k * res)


for q in range(int(input())):
	(n, m) = 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)


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	(n, m) = list(map(int, input().split()))
	repeat = n // m
	lastDigit = m % 10
	curLastDigit = lastDigit
	ct = 0
	ans = 0
	while ct < repeat and ct < 10:
		ans += curLastDigit
		curLastDigit = (lastDigit + curLastDigit) % 10
		ct += 1
	if ct < repeat:
		ans *= repeat // 10
		repeat %= 10
		ct = 0
		curLastDigit = lastDigit
		while ct < repeat:
			ans += curLastDigit
			curLastDigit = (lastDigit + curLastDigit) % 10
			ct += 1
	print(ans)


Q = int(input())
for q in range(Q):
	(N, M) = map(int, input().split())
	S = 0
	C = []
	s = 0
	for k in range(1, 11):
		if int(str(k * M)[-1]) not in C:
			C.append(int(str(k * M)[-1]))
			S = S + C[-1]
	s = 0
	D = N // M
	A = D // len(C)
	s = S * A
	A = D % len(C)
	for a in range(A):
		s = s + C[a]
	print(s)


N = int(input())
for t in range(0, N):
	L = list(map(int, input().split()))
	T = L[0]
	M = L[1]
	s = 0
	multipli = M * 10
	g = T // multipli
	r = T % multipli
	tg = 0
	tr = 0
	for n in range(M, multipli, M):
		pag = str(n)
		p = len(pag)
		cifra = int(pag[p - 1])
		tg = tg + cifra
	pm = tg * g
	for m in range(M, r + 1, M):
		pag = str(m)
		p = len(pag)
		cifra = int(pag[p - 1])
		tr = tr + cifra
	pr = tr
	s = s + pm + pr
	print(s)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	if m % 2 == 0:
		i = m
		count = 0
		while i < 5 * m:
			count += i % 10
			i += m
		s = count * (n // (5 * m))
		n = n % (m * 5)
		i = m
		count = 0
		while i <= n:
			count += i % 10
			i += m
		print(s + count)
	else:
		i = m
		count = 0
		while i < 10 * m:
			count += i % 10
			i += m
		s = count * (n // (10 * m))
		n = n % (m * 10)
		i = m
		count = 0
		while i <= n:
			count += i % 10
			i += m
		print(s + count)


k = int(input())
for _ in range(k):
	(n, m) = map(int, input().split())
	r = m % 10
	q = r
	t = r
	s = 0
	d = []
	while r != 0:
		d.append(r)
		q += t
		r = q % 10
	d.append(r)
	l = n // m
	(l, r) = divmod(l, len(d))
	s = sum(d) * l + sum(d[:r])
	print(s)


def lastDigits(m):
	a = []
	for i in range(1, 11):
		k = i * m % 10
		if k not in a:
			a.append(k)
	return a
q = int(input())
for _ in range(q):
	(n, m) = [int(x) for x in input().split()]
	(sm, b) = (0, 0)
	if n >= m:
		if n > 10:
			ldSeries = lastDigits(m % 10)
			l = len(ldSeries)
			z = n // m
			k = z % l
			z -= k
			sm += z // l * sum(ldSeries)
			b = sum(ldSeries[:k])
		else:
			for i in range(m, n + 1, m):
				sm += i % 10
	print(sm + b)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, M) = MAP()
	if N < M:
		print(0)
		continue
	lastd = int(str(M)[-1])
	cnt10 = 0
	for i in range(1, 11):
		cnt10 += int(str(lastd * i)[-1])
	(d, m) = divmod(N, M * 10)
	ans = d * cnt10
	for i in range(1, m // M + 1):
		ans += int(str(lastd * i)[-1])
	print(ans)


z = int(input())
for h in range(z):
	(n, m) = map(int, input().split())
	x = 0
	k = m
	y = n // m
	l = min(10, y)
	for i in range(l):
		if k >= 10:
			k = k % 10
		x += k
		k += m
	if y <= 10:
		print(x)
	else:
		q = y // 10
		if y >= 10:
			d = y % 10
		else:
			d = y
		sum = q * x
		k = m
		u = 0
		for i in range(d):
			if k >= 10:
				k = k % 10
			u += k
			k += m
		ans = sum + u
		print(ans)


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	(n, m) = minput()
	k = n // m
	a = [0] * 10
	for i in range(10):
		a[i] = (i + 1) * m % 10
	print(sum(a[:k % 10]) + sum(a) * (k // 10))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(end, n) = list(map(int, stdin.readline().split()))
	sm = 0
	for i in range(11):
		val = n * i % 10
		sm += val
	time = end // (n * 10)
	sm *= time
	nm = n * 10 * time
	for i in range(nm + n, end + 1, n):
		val = i % 10
		sm += val
	print(sm)


import sys
input = sys.stdin.readline
qq = int(input())
for _ in range(qq):
	(n, m) = map(int, input().split())
	num = n // m
	k = m % 10
	l = [k]
	while True:
		k = (k + m) % 10
		if k in l:
			break
		else:
			l.append(k)
	a = len(l)
	cyc = num // a
	rem = num % a
	print(cyc * sum(l) + sum(l[:rem]))


q = int(input())
for _ in range(q):
	(n, m) = [int(i) for i in input().split()]
	n = n // m
	cycle = [m * (i + 1) % 10 for i in range(10)]
	print(n // 10 * sum(cycle) + sum(cycle[:n % 10]))


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	cnt = 0
	c10 = 0
	m10 = m * 10
	for j in range(1, 11):
		c10 += m * j % 10
	cnt += c10 * (n // m10)
	x = n - n // m10 * m10
	sho = x // m
	for k in range(sho):
		cnt += (k + 1) * m % 10
	print(cnt)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = [b * i % 10 for i in range(1, 11)]
	s = 0
	h = a // (b * 10)
	s += sum(l) * h
	k = (a - h * b * 10) // b
	s += sum(l[0:k])
	print(s)


q = int(input())
while q > 0:
	q -= 1
	(n, m) = map(int, input().split())
	a = [0 for i in range(20)]
	sum = 0
	for i in range(1, 11):
		a[i] = m * i
		sum = sum + a[i] % 10
	quo = n // a[10]
	rem = n % a[10]
	c = sum * quo
	i = 1
	while a[i] <= rem:
		c = c + a[i] % 10
		i += 1
	print(c)


for q in range(int(input())):
	(n, m) = list(map(int, input().split()))
	sum1 = 0
	for i in range(1, 11):
		sum1 += m * i % 10
	x = n // m
	x1 = x // 10
	x2 = x % 10
	sum1 *= x1
	for i in range(1, x2 + 1):
		sum1 += m * i % 10
	print(sum1)


from sys import stdin, stdout
T = int(stdin.readline().rstrip())
for t in range(T):
	(n, m) = [int(x) for x in stdin.readline().rstrip().split()]
	if n > m:
		l = []
		i = m
		while True:
			x = str(i)
			y = int(x[len(x) - 1])
			if y in l:
				break
			else:
				l.append(y)
			i += m
		ans = 0
		i -= m
		if n <= i:
			j = m
			for k in range(len(l)):
				if j <= n:
					j += m
					ans += l[k]
				else:
					break
		else:
			ans += n // i * sum(l)
			k = n - n // i * i
			if k >= m:
				ans += sum(l[0:k // m])
		stdout.write(str(ans) + '\n')
	elif n < m:
		stdout.write('0\n')
	else:
		x = str(m)
		stdout.write(str(x[len(x) - 1]) + '\n')


def per(n):
	p = []
	x = n
	for i in range(1, 10):
		p += (x % 10,)
		x += n
	return p
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s = per(b)
	print(sum(s) * (a // (b * 10)) + sum(s[:a % (b * 10) // b]))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	f = 0
	s = 0
	for j in range(0, 10):
		s += m * (j + 1) % 10
	for j in range(0, n // m % 10):
		f += m * (j + 1) % 10
	print(n // m // 10 * s + f)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split(' '))
	n //= m
	digs = []
	for x in range(10):
		digs.append(m * (x + 1) % 10)
	su = 0
	for x in range(n % 10):
		su += digs[x]
	print(su + n // 10 * sum(digs))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	x = [i for i in range(10)]
	for i in range(1, 10):
		x[i] = x[i] * m % 10
	y = n // m
	z = y // 10
	y %= 10
	ans = z * sum(x) + sum(x[:y + 1])
	print(ans)


def fond(j):
	k = j % 10
	if k == 1 or k == 3 or k == 7 or (k == 9):
		return 45
	elif k == 2 or k == 4 or k == 6 or (k == 8):
		return 40
	elif k == 5:
		return 25
	else:
		return 0

def sumy(a, b):
	w = a % 10
	s = 0
	for y in range(1, b + 1):
		r = w * y % 10
		s += r
	return s
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	p = n // (10 * m)
	f = p * fond(m)
	p = n // m - 10 * p
	f += sumy(m, p)
	print(f)


import sys
T = int(input())
for i in range(T):
	(a, b) = map(int, sys.stdin.readline().split())
	n = 1
	total = 0
	X = 0
	x = []
	for j in range(1, 11):
		x.append(b * j % 10)
	X = sum(x)
	q = a // b
	r = q % 10
	q = q // 10
	total += X * q
	total += sum(x[:r])
	print(total)


q = int(input())
while q > 0:
	(n, m) = [int(x) for x in input().split()]
	lm = m % 10
	D = [lm]
	while True:
		ld = D[len(D) - 1]
		nd = (ld + lm) % 10
		if nd == lm:
			break
		D.append(nd)
	rs = sum(D)
	rl = len(D)
	pc = n // m
	fc = pc // rl
	rc = pc % rl
	print(rs * fc + sum(D[:rc]))
	q -= 1


import collections, heapq, bisect, math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def solve(A):
	(n, m) = (A[0], A[1])
	out = 0
	for i in range(1, min(10, 1 + n // m)):
		out += i * m % 10
	if n < 10 * m:
		return out
	out *= n // (10 * m)
	for i in range(n % (10 * m) // m + 1):
		out += i * m % 10
	return out
q = input()
tests = []
for test in range(int(q)):
	tests.append([int(p) for p in input().split(' ')])
for test in tests:
	print(solve(test))


from typing import List
q = int(input())

def getCLen(x: int) -> List[int]:
	cycle = []
	i = x
	while True:
		if i in cycle:
			return cycle
		cycle.append(i)
		i += x
		i %= 10
cLen = [getCLen(x) for x in range(10)]
for _ in range(q):
	(n, m) = map(int, input().strip().split())
	if n < m:
		print(0)
	else:
		cycle = cLen[m % 10]
		result = n // m // len(cycle) * sum(cycle) + sum(cycle[:n // m % len(cycle)])
		print(result)


Q = int(input())
lo = []
sm = []
for i in range(10):
	t = []
	for j in range(1, 11):
		t.append(i * j % 10)
	lo.append(t)
	sm.append(sum(t))
for i in range(Q):
	(N, M) = [int(x) for x in input().split()]
	e = int(str(M)[-1])
	ans = N // (10 * M) * sm[e] + sum(lo[e][:N % (10 * M) // M])
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	cur = 0
	extr = 0
	cur = sum([m * i % 10 for i in range(1, 11)])
	f = n // (m * 10)
	f2 = n - f * m * 10
	addi = sum([i % 10 for i in range(0, f2 + 1, m)])
	print(addi + f * cur)


a = {0: [0], 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 2: [2, 4, 6, 8, 0], 3: [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], 4: [4, 8, 2, 6, 0], 5: [5, 0], 6: [6, 2, 8, 4, 0], 7: [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], 8: [8, 6, 4, 2, 0], 9: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]}
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	ans = 0
	l = n // m
	m = int(str(m)[-1])
	cel = l // len(a[m])
	for elem in a[m]:
		ans += elem * cel
	ost = l % len(a[m])
	for j in range(ost):
		ans += a[m][j]
	print(ans)


T = int(input())
for _ in range(0, T):
	(n, m) = map(int, input().split())
	flag = 0
	L = []
	L.append(m % 10)
	p = m
	while flag == 0:
		p = p + m
		if p % 10 == L[0]:
			flag = 1
			break
		else:
			L.append(p % 10)
	N = n // m
	sumu = 0
	for i in range(0, len(L)):
		sumu += L[i]
	q = N // len(L)
	r = N % len(L)
	ans = q * sumu
	for i in range(r):
		ans += L[i]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(x, y) = divmod(n, 10 * m)
	a = sum((m % 10 * i % 10 for i in range(10)))
	b = sum((i % 10 for i in range(m, y + 1, m)))
	print(a * x + b)


def gao(a, b, c, n):
	if a == 0:
		return (n + 1) * (b // c)
	if a >= c or b >= c:
		tmp = gao(a % c, b % c, c, n)
		res = tmp + a // c * n * (n + 1) // 2 + b // c * (n + 1)
		return res
	m = (a * n + b) // c
	tmp = gao(c, c - b - 1, a, m - 1)
	res = n * m - tmp
	return res

def sum_2(n):
	return n * (n + 1) // 2

def main():
	T = int(input())
	for i in range(0, T):
		(n, m) = map(int, input().split())
		res = m * sum_2(n // m)
		res -= 10 * gao(m, 0, 10, n // m)
		print(res)
main()


t = int(input())
for _ in range(0, t):
	(n, m) = map(int, input().split())
	ss = []
	s1 = 0
	if n // m <= 10:
		for i in range(1, n // m + 1):
			k = str(i * m)[-1]
			s1 += int(k)
		print(s1)
	else:
		for i in range(1, 10):
			k = str(i * m)[-1]
			ss.append(int(k))
		s1 += sum(ss) * (n // m // 10) + sum(ss[:n // m % 10])
		print(s1)


import sys
import math

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def read():
	return int(input())

def reads():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()

def solve(n, m):
	loop = []
	cyc = n // m
	t = m % 10
	while len(loop) == 0 or loop[0] != t:
		loop.append(t)
		t = (t + m % 10) % 10
	s = 0
	for x in loop:
		s = s + x
	res = cyc // len(loop) * s
	cyc = cyc % len(loop)
	while cyc:
		res = res + loop[cyc - 1]
		cyc = cyc - 1
	return res
cas = read()
while cas:
	(n, m) = reads()
	print(solve(n, m))
	cas = cas - 1


q = int(input())
l1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
s1 = 45
l2 = [2, 4, 6, 8, 0]
s2 = 20
l3 = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
s3 = 45
l4 = [4, 8, 2, 6, 0]
s4 = 20
l5 = [5, 0]
s5 = 5
l6 = [6, 2, 8, 4, 0]
s6 = 20
l7 = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
s7 = 45
l8 = [8, 6, 4, 2, 0]
s8 = 20
l9 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
s9 = 45
for qi in range(q):
	(n, m) = (int(i) for i in input().split(' '))
	if m > n or m % 10 == 0:
		print(0)
	else:
		d = n // m
		last = m % 10
		su = d // len(eval('l%d' % last))
		su *= eval('s%d' % last)
		ite = d % len(eval('l%d' % last))
		for ii in range(ite):
			su += eval('l%d' % last)[ii]
		print(su)


def getResult(a, b):
	modTen = b % 10
	sum = modTen
	temp = modTen
	count = 1
	while temp != 0:
		temp = (temp + modTen) % 10
		sum += temp
		count += 1
	cycles = a // b
	cyclesMod = cycles % count
	cycles = cycles // count
	total = cycles * sum
	temp = 0
	for i in range(cyclesMod):
		temp = (temp + modTen) % 10
		total += temp
	return total
t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	print(getResult(a, b))


import sys
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def print_array(a):
	print(' '.join(map(str, a)))

def main():
	for _ in range(int(input())):
		(n, m) = get_ints()
		c = n // m
		a = []
		for i in range(m, n + 1, m):
			x = i % 10
			if x not in a:
				a.append(x)
			else:
				break
		l = len(a)
		s = sum(a) * (c // l) + sum(a[0:c % l]) if l > 0 else 0
		print(s)
main()


n = int(input())
for j in range(n):
	s = 0
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	u = []
	i = 0
	while i >= 0:
		if i % 10 in u:
			k = i
			break
		if i % 10 not in u:
			u.append(i % 10)
		i += b
	s = sum(u)
	ss = 0
	for i in range(a // k * k, a + 1, b):
		ss += i % 10
	sss = s * (a // k) + ss
	print(sss)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	l = []
	if a < b:
		print(0)
	else:
		r = a // b
		c = 0
		p = 0
		for i in range(1, r + 1):
			u = str(b * i)
			y = str(b * (i + 1))
			if u[-1] in l and y[-1] in l:
				break
			else:
				l.append(u[-1])
				p += int(u[-1])
				c += 1
		t = r // c
		w = p * t
		y = r % c
		z = 0
		for i in range(y):
			z += int(l[i])
		print(z + w)


def get_ans(n, m):
	max_number = n // m
	res = 0
	for i in range(1, 10):
		last_digit = m * i % 10
		if i > max_number % 10:
			number_of_occur = max_number // 10
		else:
			number_of_occur = max_number // 10 + 1
		res += number_of_occur * last_digit
	return res
q = int(input())
for i in range(q):
	(n, m) = list(map(int, input().strip().split()))
	print(get_ans(n, m))


def multiples(number):
	l = []
	for i in range(1, 11):
		mul = str(number * i)
		l.append(int(mul[len(mul) - 1]))
	for i in range(1, 10):
		l[i] += l[i - 1]
	return l
q = int(input())
while q > 0:
	q -= 1
	(n, m) = map(int, input().split())
	l = multiples(m)
	div = n // m
	if m > n:
		print(0)
	else:
		print((div - 1) // 10 * l[9] + l[div % 10 - 1])


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	div = list()
	last = m % 10
	for i in range(1, 11):
		curr = i * last % 10
		if curr not in div:
			div.append(curr)
	fac = n // m // len(div)
	ans = sum(div) * fac
	rem = n // m % len(div)
	for i in range(rem):
		ans += div[i]
	print(ans)


def solve():
	(n, m) = map(int, input().split())
	rem_set = set()
	rem = []
	cur = 0
	while True:
		cur = (cur + m) % 10
		if cur in rem_set:
			break
		rem.append(cur)
		rem_set.add(cur)
	total = n // m
	ln = len(rem)
	ans = total // ln * sum(rem) + sum(rem[:total % ln])
	print(ans)

def main():
	q = int(input())
	for _ in range(q):
		solve()
main()


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, m) = list(map(int, stdin.readline().split()))
	t = m % 10
	a = []
	for i in range(10):
		a.append(t * i % 10)
	s = sum(a)
	x = n // m
	(x, y) = divmod(x, 10)
	res = x * s + sum(a[:y + 1])
	print(res)


q = int(input())
for i1 in range(0, q):
	(n, m) = map(int, input().split())
	a = n // m
	a = str(a)
	a1 = a[0:-1]
	if len(a) == 1:
		a1 = 0
		a2 = int(a)
	else:
		a1 = int(a1)
		a2 = int(a[-1])
	sum = 0
	for i in range(1, 11):
		sum = sum + i * m % 10
	s1 = a1 * sum
	s2 = 0
	for i in range(1, a2 + 1):
		s2 = s2 + i * m % 10
	print(s1 + s2)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
msi = lambda : map(int, stdin.readline().split())
lsi = lambda : list(msi())
q = ii()
for _ in range(q):
	(n, m) = li()
	sum = 0
	k = n // m
	for i in range(1, 11):
		sum += i * m % 10
	sum *= k // 10
	for i in range(1, k % 10 + 1):
		sum += i * m % 10
	print(sum)


t = int(input())
for j in range(t):
	(n, m) = [int(x) for x in input().split()]
	total_mult = n // m
	tens = total_mult // 10
	remaining = total_mult % 10
	sum = 0
	for i in range(1, 11, 1):
		sum += m * i % 10
	sumAux = 0
	for i in range(1, remaining + 1, 1):
		sumAux += m * i % 10
	result = tens * sum + sumAux
	print(result)


def last(p):
	return int(str(p)[-1])
for _ in range(int(input())):
	(pages, a) = map(int, input().split())
	n = pages // a
	lst = a * n
	dig = int(str(a)[-1])
	if dig == 0:
		print(0)
		continue
	d = {1: [10, 45], 2: [5, 20], 3: [10, 45], 4: [5, 20], 5: [2, 5], 6: [5, 20], 7: [10, 45], 8: [5, 20], 9: [10, 45]}
	div = d[dig][0] * a
	perf = pages // div
	rem = pages % div
	ans = perf * d[dig][1]
	tmp = a
	while tmp <= rem:
		ans += last(tmp)
		tmp += a
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	k = [0] * 9
	for i in range(9):
		k[i] = int(str(m * (i + 1))[-1])
	a = n // m
	if m % 2 == 0:
		e = 4
	else:
		e = 9
	b = a % (e + 1)
	q = sum(k[:e]) * (a // (e + 1)) + sum(k[:b])
	print(q)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	t = range(m, n + 1, m)
	s = sum(map(lambda x: x % 10, t[:10]))
	print(s * (n // m // 10) + sum(map(lambda x: x % 10, t[:n // m % 10])))


def main():
	tc = int(input())
	while tc > 0:
		tc -= 1
		line = input().split()
		n = int(line[0])
		m = int(line[1])
		d = []
		for i in range(1, 11):
			d.append(i * m)
		ans = 0
		g = 10 * m
		cnt = n // g
		for i in range(10):
			ans += cnt * (d[i] % 10)
		top = g * cnt
		while top <= n:
			ans += top % 10
			top += m
		print(ans)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	n = n // m
	dp = [i * m % 10 for i in range(1, 11)]
	req = sum(dp)
	ans = 0
	for iterations in range(n % 10):
		ans += dp[iterations]
	print(ans + n // 10 * req)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	k = m
	t = 1
	s1 = k % 10
	s = s1
	while (k + m) % 10 != s1:
		k += m
		s += k % 10
		t += 1
	summa = n // m // t * s
	ost = n // m % t
	s2 = 0
	for i in range(1, ost + 1):
		s2 += i * m % 10
	print(summa + s2)


ld = [[0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8], [0, 3, 6, 9, 2, 5, 8, 1, 4, 7], [0, 4, 8, 2, 6], [0, 5], [0, 6, 2, 8, 4], [0, 7, 4, 1, 8, 5, 2, 9, 6, 3], [0, 8, 6, 4, 2], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]]
ldsum = [sum(x) for x in ld]
q = int(input())
for i in range(q):
	(n, m) = [int(x) for x in input().split()]
	a = m % 10
	if a == 0:
		print('0')
	else:
		b = n // m
		div = b // len(ld[a])
		rem = b % len(ld[a])
		print(ldsum[a] * div + sum(ld[a][:rem + 1]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	x = m
	if n < m:
		print(0)
	elif n == m:
		print(n % 10)
	else:
		temp = 0
		ans = 0
		for i in range(10):
			temp = temp + x % 10
			x = x + m
		a = n // (m * 10)
		b = n % (m * 10)
		ans = ans + temp * a
		for i in range(m, b + 1, m):
			ans = ans + i % 10
		print(ans)


T = int(input())
while T > 0:
	(M, N) = input().split()
	(M, N) = (int(M), int(N))
	totalMultiples = M // N
	unitDigitsArr = []
	(tillSum, remSum) = (0, 0)
	for digit in range(10):
		unitDigitsArr.append((digit + 1) * N % 10)
		tillSum += unitDigitsArr[digit]
	for digit in range(totalMultiples % 10):
		remSum += unitDigitsArr[digit]
	print(tillSum * (totalMultiples // 10) + remSum)
	T -= 1


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	c = 0
	if 10 * m < n:
		for i in range(m, 10 * m + 1, m):
			c += i % 10
		t = n // (10 * m)
		ans = t * c
		for i in range(t * m * 10 + m, n + 1, m):
			ans += i % 10
		print(ans)
	else:
		for i in range(m, n + 1, m):
			c += i % 10
		print(c)


for _ in range(int(input())):
	(num, div) = [int(x) for x in input().split()]
	ans = 0
	for i in range(1, 10):
		ans += i * div % 10 * (num // div // 10)
	for i in range(1, num // div % 10 + 1):
		ans += i * div % 10
	print(ans)


from sys import stdin

def solve(p, m):
	(arr, t, s) = ([], 0, 0)
	for j in range(1, 11):
		t = m % 10 * j % 10 % 10
		arr.append(t)
		s += t
	res = s * (p // (m * 10))
	t = p % (m * 10)
	for j in range(0, t // m):
		res += arr[j]
	return res
q = int(stdin.readline().rstrip())
for i in range(q):
	(p, m) = [int(x) for x in stdin.readline().rstrip().split()]
	print(solve(p, m))


from sys import stdin

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def pp(A):
	for i in A:
		print(i)

def solve():
	(n, m) = ip()
	A = []
	rs = 0
	ts = 0
	for _ in range(10):
		rs += m
		ts += rs % 10
		A.append(rs % 10)
	g = n // m
	(d, r) = (g // 10, g % 10)
	ans = d * ts
	for i in range(r):
		ans += A[i]
	return ans
t = int(input())
for _ in range(t):
	print(solve())


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ms = str(m)[-1]
	lda = []
	if ms == '0':
		lda = [0, 0]
	if ms == '1':
		lda = [i for i in range(1, 10)] + [0]
	if ms == '2':
		lda = [2, 4, 6, 8, 0]
	if ms == '3':
		lda = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
	if ms == '4':
		lda = [4, 8, 2, 6, 0]
	if ms == '5':
		lda = [5, 0]
	if ms == '6':
		lda = [6, 2, 8, 4, 0]
	if ms == '7':
		lda = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
	if ms == '8':
		lda = [8, 6, 4, 2, 0]
	if ms == '9':
		lda = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
	multiples = n // m
	per = len(lda)
	(a, b) = (multiples // per, multiples % per)
	print(sum(lda) * a + sum(lda[:b]))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = 0
	tmp = m
	for i in range(1, 11):
		a += int(str(tmp)[::-1][0])
		tmp += m
	b = n // (m * 10) * a
	cp = n % (m * 10)
	tmp = m
	a = 0
	while tmp <= cp:
		a += int(str(tmp)[::-1][0])
		tmp += m
	print(b + a)


q = int(input())
for i in range(q):
	(n, m) = input().split(' ')
	n = int(n)
	m = int(m)
	div = n // m
	last_multiple_ten_list = [unit * m % 10 for unit in range(10)]
	sum_last_multiple_ten = sum(last_multiple_ten_list)
	div_ten = div // 10
	rest = div % 10
	sum_write_numbers = div_ten * sum_last_multiple_ten
	for i in range(1, rest + 1):
		sum_write_numbers += last_multiple_ten_list[i]
	print(sum_write_numbers)


for _ in range(int(input())):
	(n, m) = tuple(map(int, input().split()))
	wholes = n // m
	tens = [int(str(i * m)[-1]) for i in range(1, 11)]
	tensum = sum(tens)
	ans = wholes // 10 * tensum
	rems = wholes % 10
	if rems != 0:
		ans += sum(tens[:rems])
	print(ans)


def find_sum_of_digits(num_pages, div):
	possible_digits = []
	dig = div % 10
	while dig not in possible_digits:
		possible_digits.append(dig)
		dig = (dig + div) % 10
	times_sum_included = num_pages // (len(possible_digits) * div)
	modulo = num_pages - len(possible_digits) * div * times_sum_included
	return sum(possible_digits) * times_sum_included + sum(possible_digits[:modulo // div])

def read_input(flag=0):
	if flag > 0:
		return int(input())
	return [int(i) for i in input().split()]
q = read_input(1)
for i in range(q):
	(n, m) = read_input()
	print(find_sum_of_digits(n, m))


n = int(input())
a = []
for i in range(n):
	s = 0
	a.append(list(map(int, input().split())))
	t = a[i][0]
	p = a[i][1]
	if t // p < 10:
		for j in range(p, t + 1, p):
			s += j % 10
	elif p % 10 == 5:
		s = t // p // 10 * 25
		for j in range(p, t // p % 10 * p + 1, p):
			s += j % 10
	elif p % 10 == 0:
		s = 0
	elif p % 2 == 0:
		s = t // p // 10 * 40
		for j in range(p, t // p % 10 * p + 1, p):
			s += j % 10
	else:
		s = t // p // 10 * 45
		for j in range(p, t // p % 10 * p + 1, p):
			s += j % 10
	print(s)


from math import ceil
sums = []
for i in range(int(input())):
	(n, m) = map(int, input().split())
	summ = 0
	a = m
	ends = []
	while a % 10 != 0:
		ends.append(a % 10)
		a += m
	ends.append(0)
	col = n // a
	summ = col * sum(ends)
	l = len(ends)
	k = 0
	for j in range(m - 1, n - a * col, m):
		summ += ends[k]
		k += 1
		if k == l:
			k = 0
	sums.append(int(summ))
for i in sums:
	print(i)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	k = n // m
	t = []
	ans = 0
	per = 1
	temp = 2 * m % 10
	sm = temp
	t.append(m % 10)
	t.append(temp + m % 10)
	while m % 10 != temp:
		temp += m
		temp %= 10
		per += 1
		sm += temp
		temp2 = t[-1]
		t.append(temp + temp2)
	del t[-1]
	t[-1] = 0
	ans = sm * (k // per) + t[k % per - 1]
	print(ans)


q = int(input())
while q > 0:
	q -= 1
	(n, m) = list(map(int, input().split()))
	mults = n // (10 * m)
	resto = n % (10 * m)
	s = 0
	for i in range(1, 10):
		s += m * i % 10
	s *= mults
	k = m
	while k <= resto:
		s += k % 10
		k += m
	print(s)


def process(n, m):
	a = n // m
	b = a % 10
	c = a // 10
	cycle = 0
	for i in range(1, 11):
		cycle = cycle + m * i % 10
	sum2 = 0
	for i in range(1, b + 1):
		sum2 = sum2 + m * i % 10
	return cycle * c + sum2
t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	print(process(n, m))


arr = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [i for i in range(9, -1, -1)]]
t = int(input())
output = []
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	o = int(m)
	m = int(m[-1])
	t = n // o
	l = len(arr[m])
	s = sum(arr[m])
	q = t // l
	r = t % l
	ans = q * s + sum(arr[m][:r])
	output.append(str(ans))
print('\n'.join(output))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print(0)
	else:
		res = 0
		if m % 2 == 1:
			s = 0
			ans = []
			for i in range(1, 10):
				tmp = m * i
				x = str(tmp)
				s += int(x[len(x) - 1])
				ans.append(int(x[len(x) - 1]))
			d = n // (m * 10)
			e = n % (m * 10)
			res += d * s
			for i in ans[:e // m]:
				res += i
		else:
			ans = []
			s = 0
			for i in range(1, 10):
				tmp = m * i
				x = str(tmp)
				s += int(x[len(x) - 1])
				ans.append(int(x[len(x) - 1]))
			d = n // (m * 10)
			e = n % (m * 10)
			res += d * s
			for i in ans[:e // m]:
				res += i
		print(res)


t = int(input())
for t1 in range(0, t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(1, 11):
		z = m * i
		z = z % 10
		if z not in l:
			l.append(z)
		else:
			break
	k = len(l)
	c = 0
	z = n // m
	n1 = z // k
	n2 = z % k
	if n1 > 0:
		c = c + sum(l) * n1
	for i in range(0, n2):
		c = c + l[i]
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(1, 11):
		arr.append(m * i % 10)
	summ = sum(arr)
	print(summ * (n // m // 10) + sum(arr[0:n // m % 10]))


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
n1 = int(z())
for _ in range(n1):
	(n, m) = map(int, z().split())
	s = []
	c = m % 10
	while c not in s:
		s.append(c)
		c = (c + m) % 10
		if c in s:
			break
	cnt = n // m
	per = cnt // len(s)
	ans = per * sum(s) + sum(s[:cnt % len(s)])
	print(ans)


num_cases = int(input())
for case in range(num_cases):
	(n, m) = [int(x) for x in input().split(' ')]
	max_range = n // m
	ans = 0
	if max_range < 10:
		for i in range(1, max_range + 1):
			ans += m * i % 10
		print(ans)
	else:
		base = 0
		fac_10 = max_range // 10
		for i in range(1, 10):
			base += m * i % 10
		base *= fac_10
		for i in range(0, max_range % 10 + 1):
			base += m * i % 10
		print(base)


T = int(input())
for _ in range(0, T):
	(n, m) = map(int, input().split())
	l = []
	l.append(m % 10)
	for i in range(1, 10):
		l.append((l[i - 1] + m) % 10)
	for i in range(1, 10):
		l[i] += l[i - 1]
	rem = n // m
	sum = l[9] * (rem // 10)
	if rem % 10 - 1 >= 0:
		sum += l[rem % 10 - 1]
	print(sum)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	li = [0] * 10
	a = x // y
	for i in range(10):
		li[i] = y * (i + 1) % 10
	rem = a - a % 10
	ans = sum(li) * (rem // 10)
	ans += sum(li[:a % 10])
	print(ans)


def solve(n, m, ans):
	if m > n:
		ans.append(0)
		return
	nums = []
	curr = m % 10
	k = 1
	while curr not in nums:
		nums.append(curr)
		k += 1
		curr = k * m % 10
	total = 0
	k -= 1
	while n > 0 and k > 0:
		total += n // (m * k) * sum(nums)
		n = n % (m * k)
		k -= 1
		nums.pop()
	ans.append(total)

def main():
	q = int(input())
	ans = []
	for i in range(q):
		(n, m) = map(int, input().split())
		solve(n, m, ans)
	for i in ans:
		print(i)
main()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	c = []
	for j in range(1, 11):
		num = m * j
		b = int(str(num)[-1])
		if b == 0:
			a.append(b)
			c.append(num)
			break
		else:
			a.append(b)
			c.append(num)
	ans = 0
	s = sum(a)
	f = n // m
	ans = ans + s * (f // len(a))
	l = f % len(a)
	for j in range(l):
		ans += a[j]
	print(ans)


for iiiii in range(int(input())):
	(n, m) = map(int, input().split())
	c = n // m
	l = []
	x = m
	if n < m:
		print(0)
		continue
	while x % 10 not in l and x <= n:
		l.append(x % 10)
		x += m
	s = sum(l)
	ans = s * (c // len(l))
	kek = m * (c // len(l) * len(l) + 1)
	while kek <= n:
		ans += kek % 10
		kek += m
	print(ans)


sums = [0] * 11
table = []
table.append(0)
for i in range(1, 10):
	x = []
	sumi = 0
	x.append(0)
	for j in range(1, 10):
		x.append(i * j % 10)
		sumi += i * j % 10
	table.append(x)
	sums[i] = sumi
T = int(input())
while T > 0:
	(a, b) = map(int, input().split())
	ans = a // (b * 10) * sums[b % 10]
	mod = a % (b * 10)
	i = 1
	if b % 10 != 0:
		while i * b <= mod:
			ans += table[b % 10][i]
			i += 1
	print(ans)
	T = T - 1


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	if m > n:
		print(0)
	else:
		a = []
		s = m
		v1 = m
		l = 0
		v = []
		while s <= n and s % 10 not in v:
			a.append([s % 10, s])
			v.append(s % 10)
			l += s % 10
			v1 += m
			s += m
		v1 -= m
		s -= m
		q = n // v1
		ans = q * l
		q = n % v1
		i = 0
		while i < len(a) and q >= a[i][1]:
			ans += a[i][0]
			i += 1
		print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if m == 1:
		s = 45 * (n // 10)
		for j in range(n % 10 + 1):
			s += j
		print(s)
	else:
		sum10 = 0
		temp = m
		s = 0
		while temp <= 10 * m and temp <= n:
			sum10 += temp % 10
			temp += m
		s += n // (10 * m) * sum10
		temp = n - n % (10 * m)
		while temp <= n:
			s += temp % 10
			temp += m
		print(s)


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
t = ii()
for i in range(t):
	(n, m) = mi()
	f = m % 10
	t = [f]
	for i in range(2, 11):
		if i * f % 10 == f:
			break
		t.append(i * f % 10)
	w = n // m
	print(sum(t) * (w // len(t)) + sum(t[:w % len(t)]))


t = int(input())
import math
while t:
	(n, m) = map(int, input().split(' '))
	s = 0
	if m % 2 == 0 and m % 10 != 0:
		x = m * 5
		q = n // x
		s = s + q * 20
		r = n % x
		q1 = r // m
		while q1 > 0:
			s1 = m * q1 % 10
			s = s + s1
			q1 -= 1
		print(s)
	elif m % 2 != 0 and m % 5 != 0:
		x = m * 10
		q = n // x
		s = s + q * 45
		r = n % x
		q1 = r // m
		while q1 > 0:
			s1 = m * q1 % 10
			s = s + s1
			q1 -= 1
		print(s)
	elif m % 2 == 0 and m % 10 == 0:
		print(0)
	else:
		d = n // m
		d = math.ceil(d / 2)
		s = s + 5 * d
		print(s)
	t = t - 1


t = int(input())

def sums(k, l):
	sum = 0
	i = 1
	while i <= l:
		sum += k * i % 10
		i += 1
	return sum
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	d = n // m
	m %= 10
	if m == 0:
		print(0)
	elif m == 5:
		res = d % 2
		print(d // 2 * 5 + res * m)
	elif m % 2 == 0:
		res = d % 5
		print(d // 5 * 20 + sums(m, res))
	else:
		res = d % 10
		print(d // 10 * 45 + sums(m, res))


q = int(input())
answers = []
for ti in range(q):
	ints = list(map(int, input().split()))
	(n, m) = (ints[0], ints[1])
	digits = {}
	mult = 1
	while True:
		s = str(mult * m)
		mult += 1
		digit = int(s[-1])
		if digit in digits:
			break
		digits[digit] = 1
	digits = list(digits.keys())
	total = 0
	mult = n // m // len(digits)
	for i in range(len(digits)):
		total += mult * digits[i]
	rem = n // m % len(digits)
	for i in range(rem):
		total += digits[i]
	rem = n % m
	answers.append(total)
for a in answers:
	print(a)


from math import *
from collections import *
from itertools import *
get = lambda : int(input())
getl = lambda : [int(x) for x in input().split()]

def main():
	for i in range(get()):
		query()

def query():
	(n, m) = getl()
	s = 0
	mul = []
	for i in range(1, 11):
		mul += [i * m % 10]
		s += i * m % 10
	b = n // m
	ans = b // 10 * s
	a = b % 10
	for i in range(a):
		ans += mul[i]
	print(ans)
main()


arr = [(0, 1, 0), (45, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0), (20, 5, 2, 4, 6, 8, 0), (45, 10, 3, 6, 9, 2, 5, 8, 1, 4, 7, 0), (20, 5, 4, 8, 2, 6, 0), (5, 2, 5, 0), (20, 5, 6, 2, 8, 4, 0), (45, 10, 7, 4, 1, 8, 5, 2, 9, 6, 3, 0), (20, 5, 8, 6, 4, 2, 0), (45, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)]
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	k = n // m
	m = m % 10
	print(k // arr[m][1] * arr[m][0] + sum(arr[m][2:k % arr[m][1] + 2]))


T = int(input())
while T:
	(n, m) = map(int, input().split())
	s = 0
	k = n % (10 * m) // m
	s = n // (10 * m)
	if str(m)[-1] == '0':
		s = 0
	elif str(m)[-1] == '2' or str(m)[-1] == '4' or str(m)[-1] == '6' or (str(m)[-1] == '8'):
		s *= 40
	elif str(m)[-1] == '5':
		s *= 25
	else:
		s *= 45
	for i in range(k + 1):
		s += int(str(i * m)[-1])
	print(s)
	T = T - 1


a = int(input())
for i in range(a):
	b = [int(i) for i in input().split()]
	c = b[0] // b[1]
	sum = 0
	sum1 = 0
	total = 0
	i = 0
	while i < 10:
		sum = sum + b[1]
		sum1 = sum1 + sum % 10
		i += 1
	d = c % 10
	total = c // 10 * sum1
	sum = 0
	sum1 = 0
	i = 0
	while i < d:
		sum = sum + b[1]
		sum1 = sum1 + sum % 10
		i = i + 1
	total = total + sum1
	print(total)


from itertools import accumulate
for tin in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(accumulate([_ * m % 10 for _ in range(10)]))
	s = n // (m * 10) * a[-1] + a[(n - n // (m * 10) * (m * 10)) // m]
	print(s)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	(ans, t1, n1) = (0, n, n)
	while n1 <= 10 * t1 and n1 <= m:
		ans += n1 % 10
		n1 += t1
	tp = m // (n * 10)
	ans *= tp
	l1 = m % (n * 10)
	while n <= l1:
		ans += n % 10
		n += t1
	print(ans)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	sum_ = 0
	t = 0
	x = 0
	if m % 10 == 0:
		sum_ = 0
	elif m % 5 == 0:
		t = n // m
		x = t // 10
		sum_ = 25 * x
		for i in range(t % 10):
			sum_ += m * (i + 1) % 10
	elif m % 2 == 0:
		t = n // m
		x = t // 10
		sum_ = 40 * x
		for i in range(t % 10):
			sum_ += m * (i + 1) % 10
	elif m % 2 != 0:
		t = n // m
		x = t // 10
		sum_ = 45 * x
		for i in range(t % 10):
			sum_ += m * (i + 1) % 10
	print(sum_)


def op():
	(c, b) = map(int, input().split())
	s = 0
	a = []
	key = b
	while key % 10 not in a:
		a.append(key % 10)
		key += b
		print(a)
		input()
	print(a)
d = int(input())
for i in range(d):
	(c, b) = map(int, input().split())
	s = 0
	a = []
	key = b
	while key % 10 not in a:
		a.append(key % 10)
		key += b
	s = sum(a) * (c // b // len(a))
	for i in range(c // b % len(a)):
		s += a[i]
	print(s)


def dprint(*ar):
	DEBUG = False
	if DEBUG:
		print(*ar)
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	sumNum = N // M
	resiNum = sumNum % 10
	Md = M % 10
	sumFirst10 = sum([Md * x % 10 for x in range(1, 10)])
	sumFirstResi = sum([Md * x % 10 for x in range(1, resiNum + 1)])
	res = sumNum // 10 * sumFirst10 + sumFirstResi
	print(res)


queries = int(input())
cycles = [[0], [0], [0], [0], [0], [0], [0], [0], [0], [0]]
for i in range(0, 10):
	for j in range(1, 10):
		if i * j % 10 != 0:
			cycles[i].append(i * j % 10)
		else:
			break
for i in range(queries):
	(n, m) = [int(x) for x in input().split()]
	quotient = n // m
	mod = quotient % len(cycles[m % 10])
	total = quotient // len(cycles[m % 10]) * sum(cycles[m % 10])
	for i in range(mod):
		total += cycles[m % 10][i + 1]
	print(total)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(1, 11):
		if m * i % 10 in l:
			break
		l.append(m * i % 10)
	s = sum(l)
	t = n // m
	ans = t // len(l) * s + sum(l[:t % len(l)])
	print(ans)


n = int(input())
for i in range(n):
	(n, m) = map(int, input().split())
	n //= m
	digit = [int((i + 1) * m % 10) for i in range(10)]
	rez = 0
	for i in range(n % 10):
		rez += digit[i]
	print(rez + n // 10 * sum(digit))


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])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(1, 10):
		l.append(int(str(m * i)[-1]))
	r = n // (m * 10) * sum(l)
	n = n % (m * 10)
	for i in range(1, 10):
		if n >= m * i:
			r += l[i - 1]
	print(r)


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


import sys
import random
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	n = n // m
	q = n // 10
	r = n % 10
	sum_10 = sum([m * i % 10 for i in range(0, 10)])
	ans = q * sum_10
	for i in range(r + 1):
		ans += m * i % 10
	print(ans)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	l = []
	for j in range(1, 10):
		edc = b * j
		l.append(int(str(edc)[-1]))
	ans = sum(l) * (a // b // 10)
	for j in range(a // b % 10):
		ans += l[j]
	print(ans)


import math
t = int(input())
summa = 0
i = 0
while i < t:
	summa = 0
	m = list(map(int, input().split()))
	if m[1] % 10 == 0:
		summa += 0
	elif m[1] % 5 == 0:
		summa += math.ceil(math.floor(m[0] / m[1]) / 2) * 5
	elif m[1] % 2 == 0:
		summa += math.floor(m[0] / m[1] / 5) * 20
		i2 = 0
		while i2 < math.floor((m[0] - math.floor(m[0] / m[1] / 5) * m[1] * 5) / m[1]):
			summa += int(str((i2 + 1) * m[1])[-1])
			i2 += 1
	else:
		summa += math.floor(m[0] / m[1] / 10) * 45
		i2 = 0
		while i2 < math.floor((m[0] - math.floor(m[0] / m[1] / 10) * 10 * m[1]) / m[1]):
			summa += int(str((i2 + 1) * m[1])[-1])
			i2 += 1
	print(summa)
	i += 1


k = int(input())
for ga in range(k):
	a = input().split()
	n = int(a[0])
	m = int(a[1])
	ga = 0
	summ = 0
	m1 = m * 2
	m1s = m
	ms = m
	summs = 0
	while int(str(m)[-1]) != int(str(m1)[-1]):
		m1 += m
		summ += int(str(m1)[-1])
		ga += 1
	ga += 1
	m1 += m
	summ += int(str(m1)[-1])
	ggg = int(n // m // ga)
	if n < m:
		print(0)
	else:
		if ggg >= 1:
			summs += ggg * summ
			if int(n // m) % ga != 0:
				for i in range(int(n // m) % ga):
					summs += int(str(m1s)[-1])
					m1s += ms
			else:
				pass
		else:
			for i in range(n // m):
				summs += int(str(m1s)[-1])
				m1s += m
		print(summs)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
it = lambda : tuple(map(int, input().split()))
ls = lambda : list(input())
l = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
t = ii()
for _ in range(t):
	(n, m) = f()
	nom = n // m
	ldgt = m % 10
	num = nom // len(l[ldgt])
	sm = num * sum(l[ldgt]) + sum((l[ldgt][i] for i in range(nom % len(l[ldgt]))))
	print(sm)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	k = n // m
	s = 0
	for i in range(1, 11):
		temp = m * i
		temp = temp % 10
		s += temp
	t = k // 10
	ans = t * s
	t = k % 10
	for i in range(1, t + 1):
		temp = m * i
		ans += temp % 10
	print(ans)


test = int(input())
for i in range(test):
	inp = input()
	inp = inp.split(' ')
	n = int(inp[0])
	m = int(inp[1])
	count = 0
	div = n // m

	def getVal(limit, val):
		multi = 0
		for i in range(1, limit + 1):
			multi += val * i % 10
		return multi
	count = 0
	if n >= m:
		count = div // 10 * getVal(10, m) + getVal(div % 10, m)
	print(int(count))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	cycles = n // (10 * m)
	cycle_value = 45
	if m % 10 == 0:
		cycle_value = 0
	elif m % 5 == 0:
		cycle_value = 25
	elif m % 2 == 0:
		cycle_value = 40
	ans += cycle_value * cycles
	n -= cycles * m * 10
	x = m
	while x <= n:
		ans += x % 10
		x += m
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	if n < m:
		print(0)
	else:
		s = 0
		for i in range(0, m * 10 + 1, m):
			s += i % 10
		s = n // (m * 10) * s
		for i in range(n // (m * 10) * m * 10, n + 1, m):
			s += i % 10
		print(s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	sum = 0
	if n < m:
		sum = 0
		print(sum)
	elif n == m:
		n = str(n)
		print(n[-1])
	else:
		n = n - n % m
		ans = n // m
		a = []
		for i in range(1, 11):
			a.append(i * m)
		if ans <= 10:
			for i in range(0, ans):
				z = str(a[i])
				sum += int(z[-1])
			print(sum)
		else:
			rem = ans % 10
			div = (ans - rem) // 10
			for i in range(0, len(a)):
				z = str(a[i])
				sum += int(z[-1]) * div
			for i in range(0, rem):
				z = str(a[i])
				sum += int(z[-1])
			print(sum)


def find_sum(n, m):
	count = 0
	m_sum = []
	for i in range(1, 11):
		m_sum.append(m * i % 10)
	total_num = n // m
	count += total_num // 10 * sum(m_sum)
	for i in range(0, total_num % 10):
		count += m_sum[i]
	return count
for _ in range(int(input())):
	print(find_sum(*map(int, input().strip().split())))


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	su = 0
	a = []
	for i in range(1, 11):
		k = i * m
		a.append(k % 10)
		su += k % 10
	x = n // m
	y = x // 10
	z = x % 10
	ans = su * y
	for i in range(z):
		ans += a[i]
	print(ans)


ll = lambda : list(map(int, input().split()))
testcases = 1
[testcases] = ll()
for _ in range(testcases):
	[n, m] = ll()
	ans = 0
	s = []
	for i in range(m, 10 * m + 1, m):
		if i % 10 in s:
			break
		s.append(i % 10)
	x = len(s)
	no = n // m // x
	re = n // m % x
	ans += no * sum(s)
	ans += sum(s[:re])
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, str(input()).split())
	p = n // m
	r = p % 10
	s = 0
	l = m % 10
	for i in range(1, 10):
		s += m * i % 10
	s1 = 0
	for i in range(1, r + 1):
		s1 += m * i % 10
	f = p // 10 * s + s1
	print(f)


q = int(input())
for i in range(q):
	(n, m) = [int(j) for j in input().split()]
	if m > n:
		print(0)
	elif m == n:
		print(m % 10)
	elif n <= 10 * m:
		const = n // m
		sum = 0
		for j in range(1, const + 1):
			sum += m * j % 10
		print(sum)
	else:
		sum = 0
		for j in range(1, 11):
			sum += m * j % 10
		const = n // m
		sum *= const // 10
		for j in range(m * (10 * (const // 10) + 1), n + 1, m):
			sum += j % 10
		print(sum)


def find_possibles(n):
	p = [n]
	i = 2
	while p[-1] % 10 != 0:
		p.append(n * i)
		i += 1
	return [i % 10 for i in p]
n = int(input())
for i in range(n):
	(pages, m) = map(int, input().split())
	possibles = find_possibles(m % 10)
	n_mul = pages // m
	n_pos = len(possibles)
	print(n_mul // n_pos * sum(possibles) + sum(possibles[:n_mul % n_pos]))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	tc = m % 10
	new = tc
	s = n // m
	if s == 0:
		print(0)
	else:
		lst = tc
		tc += new
		tc %= 10
		d = {}
		d[1] = lst
		d[2] = tc
		k = 2
		while lst != tc:
			tc += new
			k += 1
			tc %= 10
			if tc != lst:
				d[k] = tc
		k -= 1
		if s <= k:
			ans = 0
			for i in range(1, s + 1):
				ans += d[i]
			print(ans)
		else:
			dd = s % k
			ans = sum(d.values()) * (s // k)
			for i in range(1, dd + 1):
				ans += d[i]
			print(ans)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	k = n // m
	s = 0
	for i in range(1, 11):
		s += m * i % 10
	s = k // 10 * s
	for i in range(1, k % 10 + 1):
		s += m * i % 10
	print(s)


Q = int(input())
cycles = dict()
for i in range(0, 10):
	c = []
	count = 1
	while True:
		lastdigit = int(str(count * i)[-1])
		if lastdigit not in c:
			c.append(lastdigit)
		else:
			break
		count += 1
	cycles[i] = c
for k in range(Q):
	(N, M) = [int(x) for x in input().split(' ')]
	numreq = N // M
	cycledata = cycles[int(str(M)[-1])]
	print(numreq // len(cycledata) * sum(cycledata) + sum(cycledata[:numreq % len(cycledata)]))


def main():
	n1 = int(input())
	for _ in range(n1):
		(n, m) = map(int, input().rstrip().split())
		arr = []
		val = 0
		for i in range(1, 10):
			res = str(m * i)
			arr.append(int(res[-1]))
			val += int(res[-1])
		div = n // m
		mul = div // 10
		add = div % 10
		val = val * mul
		for i in range(add):
			val += arr[i]
		print(val)
main()


from sys import stdin, stdout
n = stdin.readline()
a = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
for i in range(int(n)):
	b = [int(x) for x in stdin.readline().split()]
	c = 0
	x = b[0] // b[1]
	k = b[1] % 10
	s = 0
	if k != 0:
		m = len(a[k - 1])
		s += sum(a[k - 1]) * (x // m) + sum(a[k - 1][:x % m])
	stdout.write(str(s) + '\n')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, m) = LI()
		t = [m * i % 10 for i in range(1, 11)]
		s = sum(t)
		u = n // m
		r = s * (u // 10) + sum(t[:u % 10])
		rr.append(r)
	return JA(rr, '\n')
print(main())


tc = int(input())
for _ in range(tc):
	(n, m) = list(map(int, input().split()))
	summ = 0
	total = n // m
	lis = list()
	for i in range(m, n + 1, m):
		last = str(i)[-1]
		last = int(last)
		if last not in lis:
			lis.append(last)
			total -= 1
			summ += last
		else:
			ind = lis.index(last)
			lis = lis[ind:]
			break
	if len(lis) > 0:
		ls = sum(lis)
		if total >= len(lis):
			no = total // len(lis)
			summ += ls * no
			total -= len(lis) * no
		if total > 0:
			no = lis[:total]
			summ += sum(no)
	if m == n:
		print(str(m)[-1])
	else:
		print(summ)


for i in range(int(input())):
	a = input()
	b = a.split()
	c = [int(d) for d in b]
	number_of_pages = c[0]
	divisor = c[1]
	last_digit_of_divisor = int(str(divisor)[-1])
	if last_digit_of_divisor == 1:
		l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
	elif last_digit_of_divisor == 2:
		l = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0]
	elif last_digit_of_divisor == 3:
		l = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
	elif last_digit_of_divisor == 4:
		l = [4, 8, 2, 6, 0, 4, 8, 2, 6, 0]
	elif last_digit_of_divisor == 5:
		l = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0]
	elif last_digit_of_divisor == 6:
		l = [6, 2, 8, 4, 0, 6, 2, 8, 4, 0]
	elif last_digit_of_divisor == 7:
		l = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
	elif last_digit_of_divisor == 8:
		l = [8, 6, 4, 2, 0, 8, 6, 4, 2, 0]
	elif last_digit_of_divisor == 9:
		l = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
	elif last_digit_of_divisor == 0:
		l = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	suml = number_of_pages // divisor // 10 * sum(l)
	remaining = number_of_pages // divisor % 10
	sumn = sum(l[:remaining])
	print(suml + sumn)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = [m * i % 10 for i in range(1, 11)]
	k = n // m
	ans = k // 10 * sum(l) + sum(l[0:k % 10])
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = n // m
	k = m % 10
	r = a // 10
	aa = 0
	for i in range(1, 11):
		aa += k * i % 10
	ans = r * aa
	for i in range(1, a - r * 10 + 1):
		ans += i * k % 10
	print(ans)


tensum = {0: 0, 1: 45, 2: 40, 3: 45, 4: 40, 5: 25, 6: 40, 7: 45, 8: 40, 9: 45}
t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split(' '))
	sum1 = 0
	ud = m % 10
	rangeMax = n // m
	sum1 += rangeMax // 10 * tensum[ud]
	for i in range(1, rangeMax % 10 + 1):
		sum1 += i * m % 10
	print(sum1)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	M = 10 * m
	val = 0
	for i in range(1, 10):
		val += m * i % 10
	nbm = n // M
	val *= nbm
	for i in range(nbm * M, n + 1, m):
		val += i % 10
	print(val)


def fun(i):
	freq = 2
	total = i % 10
	while i * freq % 10 != i % 10:
		total = total + i * freq % 10
		freq += 1
	return (freq - 1, total)
q = int(input())
for i in range(q):
	(n, k) = map(int, input().split())
	(freq, total) = fun(k)
	temp = n // k
	ans = temp // freq * total
	remaining = temp % freq
	for j in range(1, remaining + 1):
		ans = ans + j * k % 10
	print(ans)


for k in range(int(input())):
	(n, m) = map(int, input().split())
	b = n // m
	p = 0
	u = 0
	for h in range(1, 11):
		u += int(str(h * m)[-1])
	p += b // 10 * u
	for j in range(1, b % 10 + 1):
		p += int(str(j * m)[-1])
	print(p)


q = int(input())
for _ in range(q):
	(p, q) = list(map(int, input().split()))
	m = p // q
	n = m // 10
	m -= n * 10
	s = 0
	if n > 0:
		d = 0
		for i in range(1, 10):
			d += i * q % 10
		s = n * d
	for i in range(1, m + 1):
		s += i * q % 10
	print(s)


import math
q = int(input())
while q > 0:
	q -= 1
	n_m = input()
	n_m = n_m.split()
	n = int(n_m[0])
	m = int(n_m[1])
	i = 1
	digits = []
	summation = 0
	summation_temp = 0
	while True:
		temp = str(i * m)
		temp = int(temp[-1])
		if temp in digits or m * i > n:
			break
		else:
			digits.append(temp)
		i += 1
	if len(digits) == 0:
		print(summation)
		continue
	for i in digits:
		summation_temp = summation_temp + i
	x1 = n // m
	summation = summation_temp * (x1 // len(digits))
	for i in range(x1 - len(digits) * (x1 // len(digits))):
		summation = summation + digits[i]
	print(summation)


t = int(input())

def repeatedsum(x, k):
	l = []
	for i in range(1, k + 1):
		l.append(x * i % 10)
	return sum(l)
for i in range(t):
	(n, m) = list(map(int, input().split()))
	print(n // m // 10 * repeatedsum(m, 10) + repeatedsum(m, n // m % 10))


t = int(input())
for e in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	k = b % 10
	c = b
	ost = [0, k]
	while 1:
		c += b
		d = c % 10
		if d == k:
			break
		ost.append(d)
		ost[-1] += ost[-2]
	ost.pop()
	print(ost[-1] * (a // b // len(ost)) + ost[a // b % len(ost)])


for _ in range(int(input())):
	(n, m) = [int(__) for __ in input().split()]
	shit = 10
	if m % 10 == 0:
		shit = 1
	elif m % 5 == 0:
		shit = 2
	if m % 2 == 0 and m % 10 != 0:
		shit = 5
	l1 = []
	for i in range(1, shit + 1):
		l1.append(m * i % 10)
	print(n // (m * shit) * sum(l1) + sum(l1[:n % (m * shit) // m]))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	upto10 = 0
	mem = []
	for i in range(1, 11):
		j = i * m
		upto10 += int(str(j)[-1])
		mem.append(upto10)
	res = n // (m * 10) * upto10
	temp2 = n % (m * 10) // m
	if temp2 > 0:
		res += mem[temp2 - 1]
	print(res)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
Q = int(stdin.readline())
for q in range(Q):
	(n, m) = map(int, stdin.readline().rstrip().split())
	M = deepcopy(m)
	(ans, zz) = (0, n // m)
	if m == n:
		ans = n % 10
	elif m > n:
		ans = 0
	else:
		l = [0] * 10
		for i in range(10):
			l[i] = m % 10
			m += M
		z = zz // 10
		ans += sum(l) * z
		z = zz % 10
		ans += sum(l[:z])
	print(ans)


t = int(input())
dic = {1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 2: [2, 4, 6, 8, 0], 3: [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], 4: [4, 8, 2, 6, 0], 5: [5, 0], 6: [6, 2, 8, 4, 0], 7: [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], 8: [8, 6, 4, 2, 0], 9: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]}
for i in range(t):
	(n, m) = [int(x) for x in input().strip().split()]
	if m > n or m % 10 is 0:
		print(0)
	else:
		d = n // m
		l = m % 10
		s = sum(dic[l])
		a = d // len(dic[l])
		b = d % len(dic[l])
		ans = s * a + sum(dic[l][:b])
		print(ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	nums = []
	ans = 0
	l = 1
	arr = [0]
	i = m
	while i < n + 1:
		if i % m == 0:
			if i % 10 == 0 or i % 10 in nums:
				break
			else:
				nums.append(i % 10)
				arr.append(arr[-1] + i % 10)
				l += 1
		i += m
	tot = arr[-1]
	ans += n // (l * m) * tot + arr[n // m % l]
	print(ans)


import math

def calculate_sequence(m):
	_iter = 0
	_len = 0
	_sum = 0
	while True:
		_iter = int(str(_iter + m)[-1])
		_sum += _iter
		_len += 1
		if _iter == 0:
			break
	return (_len, _sum)

def seq_gen(m, cycles):
	_iter = 0
	while cycles > 0:
		_iter = int(str(_iter + m)[-1])
		cycles -= 1
		yield _iter

def process(n, m):
	(seq_len, seq_sum) = calculate_sequence(m)
	good_pages = n // m
	multiplier = seq_sum
	complete_sequences = good_pages // seq_len
	left_elements = good_pages % seq_len
	total = math.floor(good_pages / 10) * sum((m * (i + 1) % 10 for i in range(10))) + sum((m * (i + 1) % 10 for i in range(good_pages % 10)))
	return total
datasets = int(input())
for _ in range(datasets):
	(n, m) = [int(x) for x in input().split(' ')]
	print(process(n, m))


def solve(n, m):
	if m > n:
		return 0
	if m == n:
		x = str(m)
		return int(x[-1])
	table = [0]
	for i in range(m, 10 * m, m):
		p = str(i)
		table.append(table[-1] + int(p[-1]))
	x = n // m
	divide = x // 10
	remainder = x % 10
	return divide * table[-1] + table[remainder]
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	print(solve(n, m))


from decimal import *
tc = int(input())
for _ in range(tc):
	(n, m) = map(Decimal, input().split())
	start = m.__mod__(10)
	val = m.__mul__(Decimal(2)).__mod__(10)
	lgcycle = 1
	sum = Decimal(start)
	while val.__ne__(start):
		sum = sum.__add__(val)
		val = val.__add__(m).__mod__(10)
		lgcycle += 1
	(k, _) = n.__divmod__(m)
	(kp, rk) = k.__divmod__(lgcycle)
	res = sum.__mul__(kp)
	for i in range(int(rk)):
		res = res.__add__(m.__mul__(i + 1).__mod__(10))
	print(res)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ans = []
	res = 0
	for i in range(1, 10):
		if i * m <= n:
			ans.append(i * m % 10)
		else:
			break
	res = sum(ans)
	if res == 0:
		print(0)
		continue
	d = n // (m * 10)
	res *= d
	r = n % (m * 10)
	i = 0
	temp = 0
	temp2 = 0
	while 1:
		if temp + m <= r:
			temp += m
			temp2 += ans[i]
			i = (i + 1) % 9
		else:
			break
	res += temp2
	print(res)


n = int(input())
for i in range(n):
	(n, m) = map(int, input().split())
	full = n // (m * 10)
	print(full * sum((i % 10 for i in range(m, m * 10, m))) + sum((i % 10 for i in range(full * m * 10 + m, n + 1, m))))


q = int(input())
import math

def lcm_base(x, y):
	return x * y // math.gcd(x, y)
for _ in range(q):
	(n, m) = map(int, input().split())
	(q, r) = divmod(n, m)
	l = lcm_base(m, 10)
	s = l // m
	L = [0] * (s + 1)
	for i in range(s):
		L[i + 1] = L[i] + m * (i + 1) % 10
	(q2, r2) = divmod(q, s)
	ans = L[-1] * q2 + L[r2]
	print(ans)


import sys, itertools, math

def ia():
	return [int(i) for i in sys.stdin.readline().strip().split(' ')]

def ii():
	return int(sys.stdin.readline().strip())

def istr():
	return sys.stdin.readline().strip()
for _ in range(ii()):
	(n, m) = ia()
	D = []
	for i in range(100022222200):
		p = i * m
		if i > 0 and p % 10 == 0:
			break
		D.append(p % 10)
	rep = n // len(D) // m
	ans = sum(D) * rep
	for i in range(rep * len(D), n + 1):
		p = i * m
		if p > n:
			break
		ans += p % 10
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for k in range(t):
	(a, b) = [int(i) for i in input().split()]
	quotient = a // b
	num1 = quotient % 10
	num2 = quotient // 10
	sum1 = 0
	sum2 = 0
	n = 0
	for i in range(1, 10):
		sum1 += int(str(b * i)[-1])
		n += 1
		if n == num1:
			sum2 = sum1
	print(sum1 * num2 + sum2)


q = int(input())
d = {}
for i in range(1, 10):
	p = []
	c = 1
	while i * c % 10 not in p:
		p.append(i * c % 10)
		c += 1
	d[i] = p
d2 = {i: [sum(d[i]), len(d[i])] for i in d}
for i in range(q):
	(n, m) = list(map(int, input().split()))
	v = n // m
	key = m % 10
	if key != 0:
		div = v // d2[key][1]
		rem = v % d2[key][1]
		output = d2[key][0] * div + sum(d[key][:rem])
		print(output)
	else:
		print(0)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	r1 = range(m, m * 11, m)
	r2 = range(m, n % (m * 10) + 1, m)
	s1 = sum(map(lambda x: x % 10, r1))
	s2 = sum(map(lambda x: x % 10, r2))
	print(n // (m * 10) * s1 + s2)


from sys import stdin, stdout
T = int(stdin.readline())
for TT in range(T):
	(n, m) = map(int, stdin.readline().split())
	limit = n // m
	p = limit % 10
	ans = 0
	for x in range(1, 10):
		if x <= p:
			ans += (limit // 10 + 1) * (x * m % 10)
		else:
			ans += limit // 10 * (x * m % 10)
	stdout.write('%d\n' % ans)


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)


q = int(input())
result = []
for i in range(q):
	list_item = input().split()
	[x, y] = map(int, list_item)
	min_range = 0
	y_mul_ten = y * 10
	for ins in range(1, 10):
		min_range += y * ins % 10
	temp = x // y_mul_ten
	rem = x % y_mul_ten
	total = min_range * temp
	index = 1
	while index * y <= rem:
		total += index * y % 10
		index += 1
	result.append(total)
for i in result:
	print(i)


d = {'1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], '2': [2, 4, 6, 8, 0, 2, 4, 6, 8, 0], '3': [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], '4': [4, 8, 2, 6, 0, 4, 8, 2, 6, 0], '5': [5, 0, 5, 0, 5, 0, 5, 0, 5, 0], '6': [6, 2, 8, 4, 0, 6, 2, 8, 4, 0], '7': [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], '8': [8, 6, 4, 2, 0, 8, 6, 4, 2, 0], '9': [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]}
for x in range(int(input())):
	(m, n) = input().split()
	if n[-1] == '0':
		print(0)
	else:
		a = int(m) // (int(n) * 10)
		b = int(m) % (int(n) * 10)
		c = b // int(n)
		print(a * sum(d[n[-1]]) + sum(d[n[-1]][:c]))


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)


test = int(input())
while test:
	test -= 1
	ans = 0
	(n, m) = list(map(int, input().split()))
	a = []
	for i in range(10):
		a.append(m * (i + 1) % 10)
	s = sum(a)
	c = n // m
	ans = c // 10 * s
	for i in range(c % 10):
		ans += a[i]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = [m * i % 10 for i in range(1, 11)]
	t = n // m
	s = sum(l) * (t // 10) + sum(l[:t % 10])
	print(s)


for i in range(0, int(input())):
	(n, m) = map(int, input().split(' '))
	l = []
	for i in range(1, 11):
		l.append(int(str(i * m)[-1]))
	if n >= m:
		x = n // m
		y = int(str(x)[-1])
		if len(str(x)) > 1:
			z = int(str(x)[:-1])
		else:
			z = 0
		print(z * sum(l) + sum(l[:y]))
	else:
		print(0)


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = a[0] // a[1]
	c = a[1] % 10
	d = c
	total = 0
	e = b // 10
	f = b % 10
	for i in range(1, 11):
		total += d
		d += c
		d %= 10
	total *= e
	for i in range(1, f + 1):
		total += d
		d += c
		d %= 10
	print(total)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if m > n:
		print(0)
	else:
		d = {'0': [0], '1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], '2': [2, 4, 6, 8, 0], '3': [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], '4': [4, 8, 2, 6, 0], '5': [5, 0], '6': [6, 2, 8, 4, 0], '7': [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], '8': [8, 6, 4, 2, 0], '9': [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]}
		l = str(m)[-1]
		r = n // m
		li = d[l]
		r1 = r // len(li)
		r2 = r % len(li)
		print(int(sum(li) * r1 + sum(li[:r2])))


T = int(input())
for t in range(0, T):
	L = list(map(int, input().split()))
	N = L[0]
	M = L[1]
	somma = 0
	multipli = M * 10
	gruppi = N // multipli
	resto = N % multipli
	tgruppi = 0
	tresto = 0
	for n in range(M, multipli, M):
		pagine = str(n)
		p = len(pagine)
		cifra = int(pagine[p - 1])
		tgruppi = tgruppi + cifra
	pmultipli = tgruppi * gruppi
	for m in range(M, resto + 1, M):
		pagine = str(m)
		p = len(pagine)
		cifra = int(pagine[p - 1])
		tresto = tresto + cifra
	presto = tresto
	somma = somma + pmultipli + presto
	print(somma)


for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	old_m = m
	m = m % 10
	s = []
	s10 = 0
	for i in range(10):
		s10 += m * i % 10
		s.append(s10)
	print(n // old_m // 10 * s10 + s[n // old_m % 10])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = [0]
	while (l[-1] + m) % 10 not in l:
		l.append((l[-1] + m) % 10)
	(a, b) = divmod(n // m + 1, len(l))
	print(sum(l) * a + sum(l[:b]))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	d = []
	k = n // m
	(p, q) = divmod(k, 10)
	for i in range(1, 11):
		d.append(i * m % 10)
	ans = p * sum(d) + sum(d[:q])
	print(ans)


t = int(input())
while t > 0:
	t = t - 1
	ans = 0
	(n, m) = [int(x) for x in input().split()]
	l = []
	r = m
	s = m
	while r != 0:
		l.append(s % 10)
		r = s % 10
		s = s + m
	noofdiv = n // m
	ans = noofdiv // len(l) * sum(l)
	ind = noofdiv % len(l)
	ans = ans + sum(l[:ind])
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	k = m
	per = 0
	sum = 0
	while k <= n and k % 10 != 0:
		per += k % 10
		k += m
	if k >= n:
		print(per)
	else:
		g = n - n % k
		sum = per * (n // k)
		while g <= n:
			sum += g % 10
			g += m
		print(sum)


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


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


def findcycles(m):
	arr = [m % 10]
	t = 2
	temp = m % 10
	while arr[-1]:
		arr.append(temp * t % 10)
		t += 1
	return arr
q = int(input())
for _ in range(q):
	(n, m) = [int(x) for x in input().split(' ')]
	x = n // m
	if not x:
		print(0)
	else:
		c = findcycles(m)
		cyLen = len(c)
		indi = sum(c)
		temp = x // cyLen
		ans = temp * indi
		temp = x % cyLen
		ans += sum(c[:temp])
		print(ans)


e = int(input())
for i in range(e):
	(n, m) = map(int, input().split())
	k = n // m
	w = 2
	q = []
	while str(m)[-1] not in q:
		q.append(str(m)[-1])
		m = w * (m // (w - 1))
		w += 1
	q = list(map(int, q))
	print(sum(q) * (k // len(q)) + sum(q[:k % len(q)]))


A = [[i * j % 10 for j in range(1, 11)] for i in range(10)]
for i in range(int(input())):
	(n, m) = map(int, input().split())
	if m == 0 or m > n:
		print(0)
		continue
	print(n // (10 * m) * sum(A[m % 10]) + sum(A[m % 10][:n // m % 10]))


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = defaultdict(list)
	for i in range(e):
		(x, y) = mi()
		d[x].append(y)
		d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def Prime(x):
	if x < 2:
		return False
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			return False
	return True
t = ii()
for a0 in range(t):
	(n, m) = mi()
	if m % 10 == 0:
		print(0)
	else:
		x = n // m
		y = x % 10
		x = (x - x % 10) // 10
		if m % 5 == 0:
			x = 25 * x
		elif m % 2 == 0:
			x = 40 * x
		else:
			x = 45 * x
		for i in range(1, y + 1):
			x += int(str(m * i)[-1])
		print(x)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = 0
	for j in range(m, 10 * m, m):
		s = s + j % 10
	sum = n // (10 * m) * s
	for j in range(n // (10 * m) * (10 * m), n + 1, m):
		sum = sum + j % 10
	print(sum)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	k = m * 10
	j = 0
	for i in range(1, 11):
		l = i * m
		j += l % 10
	x = n // k
	p = x * j
	x = x * 10
	x += 1
	while 1:
		l = x * m
		if l > n:
			break
		f = l % 10
		p += f
		x += 1
	print(p)


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	x = [m * i % 10 for i in range(10)]
	for i in range(1, 10):
		x[i] += x[i - 1]
	c = n // m
	ans = c // 10 * x[-1] + x[c % 10]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	cur = start = m % 10
	cycle = [start]
	cur = (cur + start) % 10
	while cur != start:
		cycle.append(cur)
		cur = (cur + start) % 10
	Ms_in_N = n // m
	per = len(cycle)
	ans = Ms_in_N // per * sum(cycle) + sum(cycle[:Ms_in_N % per])
	print(ans)


def get_ans(n, m):
	rems = []
	for i in range(1, 11):
		b = m * i % 10
		if b in rems or m * i > n:
			break
		rems.append(b)
	k = n // m
	l = len(rems)
	if l == 0:
		return 0
	return k // l * sum(rems) + sum(rems[:k % l])

def main():
	q = int(input())
	for _ in range(q):
		(n, m) = map(int, input().split())
		print(get_ans(n, m))
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for t in range(m, m * 12, m):
		c = str(t)
		x = int(c[-1])
		if len(l) != 0 and x == l[0]:
			break
		l.append(x)
	ans = 0
	z = n // m
	zz = z // len(l)
	ans += sum(l) * zz
	modd = z % len(l)
	for i in range(modd):
		ans += l[i]
	print(ans)


t = int(input())
while t:
	mods = []
	(n, m) = map(int, input().split())
	for i in range(0, n + 1, m):
		x = i % 10
		if x in mods:
			break
		else:
			mods.append(x)
	mods.pop(0)
	mods.append(0)
	y = n // m
	(a, b) = divmod(y, len(mods))
	print(sum(mods) * a + sum(mods[:b]))
	t -= 1


q = int(input())
for i in range(q):
	(n, m) = [int(x) for x in input().split()]
	x = m
	j = s = 0
	while x % 10 != m % 10 or j == 0:
		j += 1
		s += x % 10
		x += m
	x -= m
	y = n // x
	arr = y * s
	for i in range(x * y, n + 1, m):
		arr += i % 10
	print(arr)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	cikl = []
	for j in range(1, 10):
		cikl.append(j * m % 10)
	n //= m
	print(sum(cikl[:n % 10]) + sum(cikl) * (n // 10))


t = int(input())
while t:
	(n, m) = list(map(int, input().split()))
	x = []
	for i in range(1, 11):
		c = m * i
		d = str(c)
		d = int(d[len(d) - 1])
		x.append(d)
	s = sum(x)
	n = n // m
	r = n % 10
	n = n // 10
	ans = s * n + sum(x[0:r])
	print(ans)
	t -= 1


for i in ' ' * int(input()):
	(a, b) = map(int, input().split())
	d = int(str(b)[-1])
	c = [int(str(d * i)[-1]) for i in range(1, 11)]
	k = a // b
	print(sum(c) * (k // 10) + sum(c[:k % 10]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	k = n // m
	li = []
	for i in range(1, 11):
		li.append(m * i % 10)
	b = sum(li)
	s = b * (k // 10) + sum(li[:k % 10])
	print(s)


from math import ceil
q = int(input())
while q > 0:
	(n, m) = map(int, input().split())
	ans = 0
	dig = []
	if m % 10 == 0:
		ans = 0
	elif m % 5 == 0:
		mul = n // m
		mul = ceil(mul / 2)
		ans = mul * 5
	elif m % 2:
		ans += n // (m * 10) * 45
		n -= n // (m * 10) * (m * 10)
		for i in range(0, n + 1, m):
			ans += i % 10
	else:
		ans += 20 * (n // (m * 5))
		n -= n // (m * 5) * (m * 5)
		for i in range(0, n + 1, m):
			ans += i % 10
	print(ans)
	q -= 1


l = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0]]
n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	A = int(p[0])
	B = int(p[1])
	if A < B:
		print(0)
	elif A == B:
		H = list(p[0])
		H.reverse()
		print(H[0])
	else:
		H = list(p[1])
		H.reverse()
		C = A // B
		D = len(l[int(H[0]) - 1])
		E = C // D
		F = C % D
		S = 0
		for j in range(0, len(l[int(H[0]) - 1])):
			S += E * l[int(H[0]) - 1][j]
		for j in range(0, len(l[int(H[0]) - 1])):
			if F > 0:
				S += l[int(H[0]) - 1][j]
				F -= 1
		print(S)


def mp():
	return map(int, input().split())
q = int(input())
for qq in range(q):
	(n, m) = mp()
	ans = m % 10
	mm = m
	while mm <= n and mm % 10 != 0:
		mm += m
		ans += mm % 10
	ans = n // mm * ans
	mm = n // mm * mm
	while mm <= n:
		ans += mm % 10
		mm += m
	print(ans)


n = int(input())
for qqq in range(n):
	s = input().split(' ')
	st = int(s[0])
	m = int(s[1])
	if m % 10 == 0:
		print(0)
	else:
		if int(s[1][-1]) == 1:
			mas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
		elif int(s[1][-1]) == 2:
			mas = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0]
		elif int(s[1][-1]) == 3:
			mas = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
		elif int(s[1][-1]) == 4:
			mas = [4, 8, 2, 6, 0, 4, 8, 2, 6, 0]
		elif int(s[1][-1]) == 5:
			mas = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0]
		elif int(s[1][-1]) == 6:
			mas = [6, 2, 8, 4, 0, 6, 2, 8, 4, 0]
		elif int(s[1][-1]) == 7:
			mas = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
		elif int(s[1][-1]) == 8:
			mas = [8, 6, 4, 2, 0, 8, 6, 4, 2, 0]
		elif int(s[1][-1]) == 9:
			mas = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
		summa = sum(mas)
		tt = st // m
		print(tt // 10 * summa + sum(mas[:tt % 10]))


q = int(input())
v = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
for i in range(q):
	(x, y) = map(int, input().split())
	y1 = y % 10
	s = x // y
	f = s // len(v[y1 - 1])
	c = s % len(v[y1 - 1])
	if y1 == 0:
		print(0)
	else:
		d = f * sum(v[y1 - 1]) + sum(v[y1 - 1][:c])
		print(d)


ar = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]

def fun(a, b):
	x = a // len(ar[b - 1])
	c = a % len(ar[b - 1])
	return sum(ar[b - 1]) * x + sum(ar[b - 1][:c])
for q in range(0, int(input())):
	(n, m) = [int(x) for x in input().split()]
	y = m % 10
	if y != 0:
		res = fun(n // m, y)
		print(res)
	else:
		print(0)


for i in range(int(input())):
	inp = list(map(int, input().split()))
	n = inp[0]
	m = inp[1]
	count = n // m
	answer = 0
	qw = int(str(m)[-1])
	c = 2
	value = int(str(qw * 2)[-1])
	s = qw + value
	while value != qw:
		c += 1
		value = int(str(qw * c)[-1])
		s += value
	c -= 1
	s -= value
	answer += s * (count // c)
	for i in range(1, 1 + count % c):
		answer += int(str(qw * i)[-1])
	print(answer)


t = int(input())
b = []
for i in range(t):
	a = list(map(int, input().split()))
	b.append(a)
for i in b:
	n = i[0]
	m = i[1]
	s = []
	t = 0
	for p in range(1, 11):
		s.append(t)
		t += m * p % 10
	s.append(t)
	a = n // m
	c = a // 10
	d = a % 10
	sum = c * t + s[d]
	print(sum)


v = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0]]
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().strip().split()))
	c = a // b
	d = int(str(b)[-1])
	e = v[d - 1]
	f = c % len(e)
	g = c // len(e)
	h = sum(e)
	j = sum(e[:f])
	print(h * g + j)


import sys
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	a = []
	a.append(0)
	c = 0
	for i in range(m, n + 1, m):
		if c == 10:
			break
		a.append(a[c] + i % 10)
		c += 1
	t1 = n // (m * 10)
	ans = a[c] * t1
	t2 = (n - t1 * m * 10) // m
	ans += a[t2]
	print(ans)


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)


for tt in range(int(input())):
	(n, m) = map(int, input().split())
	table = [m % 10]
	for i in range(2, 11):
		table.append(m * i % 10 + table[i - 2])
	mul = n // m
	if mul == 0:
		print(0)
		continue
	ans = mul // 10 * table[9]
	if mul % 10:
		ans += table[mul % 10 - 1]
	print(ans)


def inp():
	return map(int, input().split())
from math import *
q = int(input())
for i in range(q):
	(n, m) = inp()
	(out, dig) = (0, m % 10)
	if dig == 5:
		if n // m % 2:
			out = ceil(n // m / 2) * 5
		else:
			out = n // m // 2 * 5
	elif dig == 0:
		out = 0
	elif dig % 2:
		(div, count) = (n // m, dig)
		out += div // 10 * 45
		for i in range(div % 10):
			if count > 9:
				count %= 10
			out += count
			count += dig
	else:
		(div, count) = (n // m, dig)
		out += div // 5 * 20
		for i in range(div % 5):
			if count > 9:
				count %= 10
			out += count
			count += dig
	print(out)


q = int(input())
for z in range(q):
	(n, m) = map(int, input().split())
	bk = [m % 10]
	tek = (m % 10 + m % 10) % 10
	while bk[0] != tek:
		bk.append(tek)
		tek = (tek + m % 10) % 10
	raz = n // m
	ans = sum(bk) * (raz // len(bk))
	raz -= raz // len(bk) * len(bk)
	for i in range(raz):
		ans += bk[i]
	print(ans)


n = 0
m = 0
t = 0
t = int(input())
while t > 0:
	(n, m) = input().split(' ')
	n = int(n)
	m = int(m)
	sum = 0
	sumt = 0
	k = 0
	for i in range(1, 11):
		k = m * i
		sumt += k % 10
	k = 0
	a = int(n / (m * 10))
	sum = sumt * a
	a = a * (m * 10)
	while a < n:
		a += m
		if a > n:
			break
		sum += a % 10
	print(sum)
	t -= 1


import sys
input = sys.stdin.readline
from collections import *
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	l = []
	for i in range(1, 15):
		v = i * m % 10
		if v in l:
			break
		l.append(v)
	c = n // m
	ans = c // len(l) * sum(l) + sum(l[:c % len(l)])
	print(ans)


import math
k = int(input().strip())
for i in range(k):
	[n, m] = list(map(int, input().strip().split()))
	seq = [x * m % 10 for x in range(1, 11)]
	number_of_times = math.floor(n // m)
	print(int(sum(seq) * math.floor(number_of_times // 10) + sum(seq[:math.floor(number_of_times % 10)])))


qi = []
for i in range(10):
	temp = []
	for j in range(1, 11):
		temp.append(int(str(i * j)[-1]))
	qi.append(temp)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	digit = int(str(m)[-1])
	div = n // m
	q = div // 10
	r = div % 10
	summ = sum(qi[digit])
	print(q * summ + sum(qi[digit][:r]))


q = int(input())
for p in range(q):
	(n, m) = map(int, input().split())
	w = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	z = []
	s = n // m
	x = s // 10
	sum = 0
	for i in w:
		t = int(str(i * m)[-1])
		z.append(t)
		sum += x * t
	for i in range(s % 10):
		sum += z[i]
	print(sum)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print(0)
		continue
	l = [0 for i in range(10)]
	x = n // m
	for i in range(1, 11):
		l[i - 1] = m * i % 10
	res = sum(l) * (x // 10) + sum(l[:x % 10])
	print(res)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if n == m:
		print(n % 10)
		continue
	if n < m:
		print(0)
		continue
	sum = 0
	f = 0
	for i in range(1, 11):
		if n - m * i < 0:
			f = 1
			break
		sum = sum + m * i % 10
	if f == 1:
		print(sum)
		continue
	res = 0
	k = int((n + m - 1) / m / 10)
	mm = m * k * 10
	res = sum * k
	for i in range(1, 11):
		if n - (mm + i * m) < 0:
			break
		res = res + (mm + i * m) % 10
	print(res)


import math

def main():
	q = int(input())
	for _ in range(q):
		(n, m) = map(int, input().split())
		if m > n:
			print(0)
			continue
		d = m + m
		s = set()
		s.add(m)
		while d % 10 != m % 10 and d <= n:
			s.add(d)
			d += m
		d -= m
		ans = 0
		for i in s:
			k = max(0, (n - i) // d) + 1
			ans += k * (i % 10)
		print(ans)
main()


Q = int(input())
ans = []
for _ in range(Q):
	(N, M) = map(int, input().split())
	v = 0
	k = 10
	s = 0
	for i in range(10):
		v = (v + M) % 10
		s += v
		if v == 0:
			k = i + 1
			break
	p = N // (k * M)
	q = N % (k * M)
	r = p * s
	for v in range(0, q + 1, M):
		r += v % 10
	ans.append('%d\n' % r)
open(1, 'w').writelines(ans)


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


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = []
	c = m % 10
	while c not in s:
		s.append(c)
		c = (c + m) % 10
	ind = s.index(c)
	cnt = n // m
	per = cnt // len(s)
	ans = per * sum(s) + sum(s[:cnt % len(s)])
	print(ans)


import sys
in_file = sys.stdin
q = int(in_file.readline().strip())
for _ in range(q):
	(n, m) = map(int, in_file.readline().strip().split())
	A = [m * i % 10 for i in range(10)]
	n = n // m
	res = sum(A) * (n // 10) + sum(A[1:n % 10 + 1])
	sys.stdout.write(str(res) + '\n')
sys.stdout.flush()


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	if m > n:
		print(0)
	else:
		divs = n // m
		ldm = m % 10
		rot = [ldm * i % 10 for i in range(1, 10)] + [0]
		sm = sum(rot) * (divs // 10)
		for i in range(divs % 10):
			sm += rot[i]
		print(sm)


q = int(input())
for i in range(q):
	(n, m) = [int(x) for x in input().split()]
	k = n // m
	const_m = m % 10
	m %= 10
	summ = 0
	x = k // 10
	for j in range(10):
		summ += m
		m = (m + const_m) % 10
	summ *= x
	y = k % 10
	m = const_m
	for j in range(y):
		summ += m
		m = (m + const_m) % 10
	print(summ)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	div = n // m
	ans = 0
	for i in range(10):
		ans += i * m % 10 * ((div - i) // 10 + 1)
	print(ans)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
nb_test = RI()
for _ in range(nb_test):
	(n, m) = RMI()
	tens = [i * m % 10 for i in range(1, 10)]
	(main, rest) = divmod(n // m, 10)
	answ = main * sum(tens) + sum(tens[:rest])
	print(answ)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	if m % 10 == 0:
		print(0)
	elif n >= m:
		s = 0
		l = []
		m = str(m)
		x = int(m[-1])
		m = int(m)
		for i in range(1, x * 10):
			if i % x == 0:
				s = s + i % 10
				l.append(i % 10)
		e = n // (m * 10)
		x = n % (m * 10) // m
		s = s * e
		for j in range(x):
			s = s + l[j]
		print(s)
	else:
		print(0)


t = int(input())
for w in range(t):
	(n, m) = map(int, input().split())
	i = 1
	c = m * i
	r = []
	while i <= 10:
		r.append(int(str(c)[-1]))
		i += 1
		c = m * i
	c = n // m
	ans = sum(r) * (c // 10)
	for i in range(c % 10):
		ans += r[i]
	print(ans)


t = int(input())
ans = []
for _ in range(t):
	arr = list(map(int, input().split()))
	n = arr[0]
	m = arr[1]
	cur_arr = []
	for i in range(m, m * 10 + 1, m):
		cur_arr.append(i % 10)
	residual = n % (10 * m)
	residual /= m
	s = sum(cur_arr)
	s *= n // (10 * m)
	s += sum(cur_arr[:int(residual)])
	ans.append(s)
for el in ans:
	print(el)


def g(n, q):
	s = 0
	for i in range(1, n + 1):
		s = s + i * q % 10
	return s

def main():
	(n, q) = map(int, input().split())
	dc = [0, 45, 40, 45, 40, 25, 40, 45, 40, 45]
	ans = n // (10 * q) * dc[q % 10]
	print(g((n - n // (10 * q) * 10 * q) // q, q) + ans)
n = int(input())
for i in range(n):
	main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(1, 10):
		a.append(i * m % 10)
	print(sum(a) * (n // m // 10) + sum(a[:n // m % 10]))


querries = int(input())
for i in range(querries):
	line = input().split()
	num_pages = int(line[0])
	m = int(line[1])
	num_divisors = num_pages // m
	last_digit = m % 10
	cicle = []
	multiplier = 1
	while not last_digit * multiplier % 10 in cicle:
		cicle.append(last_digit * multiplier % 10)
		multiplier += 1
	sum_cicle = 0
	for digit in cicle:
		sum_cicle += digit
	total = sum_cicle * (num_divisors // len(cicle))
	for i in range(num_divisors % len(cicle)):
		total += cicle[i]
	print(total)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	a = [0] * 10
	for j in range(10):
		a[j] = m * (j + 1) % 10
	t = n // m
	b = t // 10
	c = t % 10
	s = b * sum(a) + sum(a[0:c])
	print(s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	p = [m * (i + 1) % 10 for i in range(10)]
	k = n // m
	x = sum(p) * (k // 10) + sum(p[:k % 10])
	print(x)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	rep = []
	now = 0
	for i in range(20):
		now += m
		if len(rep) > 0 and now % 10 == rep[0]:
			break
		else:
			rep.append(now % 10)
	r = len(rep)
	ANS = 0
	ANS += n // m // r * sum(rep)
	now = n // m // r * r * m
	for i in range(20):
		now += m
		if now > n:
			break
		ANS += now % 10
	print(ANS)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	k = 0
	for j in range(m, 10 * m, m):
		k += j % 10
	x = n // (10 * m)
	sum = x * k
	y = x * (10 * m)
	for j in range(y, n + 1, m):
		sum += j % 10
	print(sum)


array0 = [0]
array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
array2 = [2, 4, 6, 8, 0]
array3 = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
array4 = [4, 8, 2, 6, 0]
array5 = [5, 0]
array6 = [6, 2, 8, 4, 0]
array7 = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
array8 = [8, 6, 4, 2, 0]
array9 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
array = [array0, array1, array2, array3, array4, array5, array6, array7, array8, array9]
q = int(input())
for _ in range(q):
	(n, m) = input().split()
	m_last = int(m[-1])
	(m, n) = (int(m), int(n))
	count = n // m
	quot = count // len(array[m_last])
	rem = count % len(array[m_last])
	total = quot * sum(array[m_last]) + sum(array[m_last][:rem])
	print(total)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		sm = 0
		lis = [0]
		ind = 10
		for i in range(1, 10):
			num = m * i
			if num % 10 == 0:
				ind = i
				break
			else:
				num = num % 10
				sm += num
				lis.append(sm)
		div = n // m
		value = div // ind
		ans = value * sm
		rem = div % ind
		ans += lis[rem]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for nt in range(t):
	(n, m) = map(int, input().split())
	num = n // 10
	new = num // m
	x = int(str(m)[-1])
	if x == 1 or x == 3 or x == 7 or (x == 9):
		ans = new * 45
		num2 = n - new * m * 10
		for i in range(1, 10):
			if m * i <= num2:
				ans += int(str(m * i)[-1])
			else:
				break
	elif x == 4 or x == 8 or x == 2 or (x == 6):
		ans = new * 40
		num2 = n - new * m * 10
		for i in range(1, 10):
			if m * i <= num2:
				ans += int(str(m * i)[-1])
			else:
				break
	elif x == 0:
		ans = 0
	else:
		ans = new * 25
		num2 = n - new * m * 10
		for i in range(1, 10):
			if m * i <= num2:
				ans += int(str(m * i)[-1])
			else:
				break
	print(ans)


q = int(input())
for __ in range(q):
	(n, m) = [int(i) for i in input().split()]
	soma = 0
	count = n // m
	digitos = []
	numero = 0
	while True:
		numero += m
		digito = numero % 10
		digitos.append(digito)
		if digito == 0:
			break
	vezes = count // len(digitos)
	resto = count % len(digitos)
	soma += vezes * sum(digitos)
	soma += sum(digitos[:resto])
	print(soma)


for _ in range(int(input())):
	(n, m) = 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)]))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	if n >= m:
		a = []
		temp = m
		Sum_digit = 0
		for j in range(1, 11):
			a.append(temp * j % 10)
		Sum_digit = sum(a)
		total_sum = n // (m * 10) * Sum_digit
		new_no = n - n // (m * 10) * (m * 10)
		k = 0
		for j in range(new_no // m):
			total_sum += a[j]
		print(total_sum)
	else:
		print(0)


from sys import stdin, stdout
from collections import Counter
import math

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

def r_str():
	return stdin.readline().rstrip()

def rsingle_char():
	return stdin.read(1)

def sortFirst(val):
	return val[0]

def main():
	q = rsingle_int()
	for i in range(q):
		(n, m) = rmult_int()
		m_cnt = n // m
		if m_cnt == 0:
			print(0)
		else:
			sum = m % 10
			period = sum
			cur_cnt = 1
			m_cnt -= 1
			while m_cnt > 0:
				period = (period + m) % 10
				sum += period
				cur_cnt += 1
				m_cnt -= 1
				if period == 0:
					num_periods = n // (cur_cnt * m) - 1
					sum += sum * num_periods
					m_cnt -= num_periods * cur_cnt
					cur_cnt = 0
			print(sum)
main()


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 i in range(q):
	(n, m) = [int(x) for x in input().split()]
	numberOfTimes = n // m // 10
	count = 0
	sum = 0
	for i in range(1, 11, 1):
		sum += m * i % 10
	count = sum * numberOfTimes
	rest = n // m % 10
	for j in range(1, rest + 1, 1):
		count += m * j % 10
	print(count)


q = int(input())
for i in range(q):
	lst = [int(i) for i in input().split()]
	n = lst[0]
	m = lst[1]
	k = 0
	for j in range(m, 10 * m, m):
		k += j % 10
	s = n // (10 * m) * k
	for j in range(n // (10 * m) * (10 * m), n + 1, m):
		s += j % 10
	print(s)


dp = [0] * 10

def calc_ans(n, m):
	sum = 0
	for i in range(1, m + 1):
		sum = sum + n * i % 10
	return sum
for i in range(1, 10):
	sum = calc_ans(i, 9)
	dp[i] = sum
q = int(input())
while q:
	(n, m) = [int(x) for x in input().split()]
	ans = n // m // 10 * dp[m % 10] + calc_ans(m % 10, n // m % 10)
	print(ans)
	q = q - 1


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	s = 0
	do = n // m
	di = do // 10
	l = []
	for j in range(1, 11):
		l.append(j * m % 10)
	for j in range(10):
		s += di * l[j]
	for j in range(do - di * 10):
		s += l[j]
	print(s)


import math
from decimal import Decimal
q = int(input())
for k in range(q):
	(n, m) = map(int, input().split())
	yek = m % 10
	ans = 0
	a = math.floor(Decimal(n) / Decimal(m))
	b = math.floor(a / 10)
	for i in range(b * 10 + 1, a + 1):
		e = yek * i
		e %= 10
		ans += e
	c = 0
	for i in range(0, 11):
		c += i * yek % 10
	c *= b
	ans += c
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	if m > n:
		print(0)
	else:
		ans = 0
		cycle = 0
		sum = 0
		if m % 10 == 0:
			print(0)
			continue
		elif m % 5 == 0:
			cycle = m * 2
			sum = 5
		elif m % 2 == 0:
			cycle = m * 5
			sum = 20
		else:
			cycle = 10 * m
			sum = 45
		x = n // cycle
		y = n % cycle
		ans = x * sum
		i = 1
		while i * m <= y:
			ans += i * m % 10
			i += 1
		print(ans)


def main():

	def solve():
		(n, m) = map(int, input().split())
		p = n // m
		if m % 10 == 0:
			print(0)
		elif m % 5 == 0:
			print((p + 1) // 2 * 5)
		elif m % 2 == 0:
			result = 20 * (p // 5)
			for i in range(1, p % 5 + 1):
				result += m * i % 10
			print(result)
		else:
			result = 45 * (p // 10)
			for i in range(1, p % 10 + 1):
				result += m * i % 10
			print(result)
	q = int(input())
	for _ in range(q):
		solve()
main()


q = int(input())
for t in range(q):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	x = m
	p = [x % 10]
	i = 1
	ans = 0
	while (x + m) % 10 != m % 10:
		i += 1
		x += m
		p.append(x % 10)
	s = sum(p)
	ans1 = n // x * s + sum(p[:(n - n // x * x) // m])
	print(ans1)


for _ in range(int(input())):
	(m, n) = map(int, input().split(' '))
	l = []
	now = n
	while 1:
		if now % 10 in l:
			break
		l.append(now % 10)
		now += n
	how = m // n
	ss = sum(l)
	ans = ss * (how // len(l))
	how %= len(l)
	ans += sum(l[:how])
	print(ans)


for query in range(int(input().strip())):
	(n, m) = [int(i) for i in input().strip().split(' ')]
	base = 0
	for i in range(1, 10):
		base += m * i % 10
	res = base * (n // (m * 10))
	r = n % (m * 10)
	for i in range(1, 10):
		if m * i > r:
			break
		res += m * i % 10
	print(res)


def main():
	q = int(input())
	for qq in range(q):
		(n, m) = map(int, input().split())
		upper_k = n // m
		ans = 0
		seq = []
		for k in range(1, upper_k + 1):
			term = k * m % 10
			if term in seq:
				break
			seq.append(term)
		if len(seq) == 0:
			print(0)
			continue
		total_intervals = upper_k // len(seq)
		remaining_interval = upper_k % len(seq)
		ans = sum(seq) * total_intervals
		for i in range(remaining_interval):
			ans += seq[i]
		print(ans)
main()


l = [45, 40, 45, 40, 25, 40, 45, 40, 45, 0]
for i in range(int(input())):
	(a, b) = map(int, input().split())
	r = b % 10
	n = a // b
	nr = n % 10
	n = (n - nr) // 10
	s = n * l[r - 1]
	for i in range(1, nr + 1):
		s += i * r % 10
	print(s)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	k = n // m
	ldig = []
	for i in range(10):
		ldig.append(m * i % 10)
	print(k // 10 * sum(ldig) + sum(ldig[:k % 10 + 1]))


import math
q = int(input())
for k in range(q):
	(n, m) = input().split(' ')
	n = int(n)
	m = int(m)
	if n == m:
		print(int(str(m)[-1]))
	elif m > n:
		print(0)
	else:
		lastdigit = int(str(m)[-1])
		if lastdigit == 0:
			print(0)
		else:
			paMax = n - n % m
			if lastdigit in [1, 3, 7, 9]:
				a = math.floor((paMax - m) / (10 * m))
				lastSum = a * 45
				actualNumber = m + a * 10 * m
			elif lastdigit in [2, 4, 6, 8]:
				a = math.floor((paMax - m) / (5 * m))
				lastSum = a * 20
				actualNumber = m + a * 5 * m
			else:
				a = math.floor((paMax - m) / (2 * m))
				lastSum = a * 5
				actualNumber = m + a * 2 * m
			while actualNumber <= paMax:
				lastdigit = int(str(actualNumber)[-1])
				lastSum += lastdigit
				actualNumber += m
			print(lastSum)


t = int(input(''))
arr = []
for i in range(t):
	arr.append(list(map(int, input().split())))
for i in arr:
	n = i[0]
	m = i[1]
	s = 0
	for j in range(1, 11):
		s += m * j % 10
	tot = n // (m * 10)
	if tot * m * 10 == n:
		print(s * tot)
	else:
		s = s * tot
		rem = n - tot * m * 10
		left = rem // m
		for j in range(1, left + 1):
			s += m * j % 10
		print(s)


def odds(a1, n, m):
	bb = m % 10 * 10 + 100 * (m // 10)
	aa = n // bb * bb
	return sum(a1) * (n // bb) + sum(a1[:int((n - aa) / bb * 10)])

def evens(a1, n, m):
	c1 = m % 10 * 5 + 50 * (m // 10)
	return 20 * (n // c1) + sum(a1[:int(n % c1 / c1 * 10 / 2)])
q = int(input().strip())
for _ in range(q):
	addUp = 0
	store = []
	(n, m) = map(int, input().strip().split())
	if m % 10 == 0:
		result = 0
	if m % 10 == 1:
		a1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
		result = odds(a1, n, m)
	if m % 10 == 3:
		a1 = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
		result = odds(a1, n, m)
	if m % 10 == 7:
		a1 = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
		result = odds(a1, n, m)
	if m % 10 == 9:
		a1 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
		result = odds(a1, n, m)
	if m % 10 == 2:
		a1 = [2, 4, 6, 8, 0]
		result = evens(a1, n, m)
	if m % 10 == 4:
		a1 = [4, 8, 2, 6, 0]
		result = evens(a1, n, m)
	if m % 10 == 6:
		a1 = [6, 2, 8, 4, 0]
		c1 = m % 10 * 5 + m // 10 * 50
		result = evens(a1, n, m)
	if m % 10 == 8:
		a1 = [8, 6, 4, 2, 0]
		result = evens(a1, n, m)
	if m % 10 == 5:
		if 0 <= n % (m * 2) <= m // 10 * 10 + 4:
			a = n - n % (m * 2)
			resu = int(a / m / 2)
		else:
			a = n + (m - n % (m * 2))
			resu = int((a - m) / m / 2) + 1
		result = resu * 5
	print(result)


T = int(input())
for i in range(T):
	(n, m) = map(int, input().split())
	x = n // m
	(a, b) = (x // 10, x % 10)
	s = sum((k * m % 10 for k in range(1, 10)))
	p = sum((k * m % 10 for k in range(1, b + 1)))
	print(a * s + p)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		lcm = m % 10 * 10 // math.gcd(10, m % 10)
		temp = m % 10
		mod = [temp]
		while temp < lcm:
			temp += m % 10
			mod.append(temp % 10)
		(s, t) = (n // m // len(mod), n // m % len(mod))
		print(s * sum(mod) + sum(mod[:t]))
main()


MAX_INT = int(1000000000.0 + 7)
q = int(input())
for request in range(q):
	(n, m) = map(int, input().split())
	b = n // m
	c = b // 10
	x = b % 10
	steps = [m * i % 10 for i in range(1, 10)]
	ans = sum(steps) * c
	ans += sum(steps[:x])
	print(ans)


def f(n, m):
	s = 0
	if n > m * 10:
		for i in range(m, m * 10, m):
			s += int(str(i)[len(str(i)) - 1])
		s = s * int(n / (m * 10))
		for i in range(m * int(n / (m * 10)) * 10, n + 1, m):
			s += int(str(i)[len(str(i)) - 1])
		return s
	else:
		for i in range(m, n + 1, m):
			s += int(str(i)[len(str(i)) - 1])
		return s
nt = int(input())
ans = []
for i in range(nt):
	(n, m) = input().split()
	ans.append(f(int(n), int(m)))
for i in ans:
	print(i)


chains = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]

def last_digit(n):
	x = str(n)
	return int(x[-1])

def solve(n, m):
	n_d = n // m
	l_d = last_digit(m)
	ret = n_d // len(chains[l_d]) * sum(chains[l_d])
	rem = n_d % len(chains[l_d])
	i = 0
	while rem > 0:
		ret += chains[l_d][i]
		i += 1
		rem -= 1
	return ret

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = list(map(int, input().strip().split()))
		print(solve(n, m))
main()


q = int(input())

def func(n, m):
	sum = 0
	x = n // m
	a = x // 10
	b = x % 10
	if m % 2 != 0:
		if m % 5 == 0:
			sum = a * 25
		else:
			sum = a * 45
	elif m % 10 == 0:
		sum = 0
	else:
		sum = a * 40
	for i in range(1, b + 1):
		sum = sum + int(str(i * m)[-1])
	return sum
for _ in range(q):
	l = list(map(int, input().split()))
	(n, m) = (l[0], l[1])
	print(func(n, m))


t = int(input())
for x in range(t):
	a = list(map(int, input().split(' ')))
	b = a[0]
	c = a[1]
	d = b // c
	if d > 10:
		nl = 0
		m = c
		arr = []
		while nl < 10:
			arr.append(m % 10)
			m += c
			nl += 1
		div = d // 10
		rem = d % 10
		ans = div * sum(arr)
		ans += sum(arr[:rem])
	else:
		m = c
		arr = []
		while d != 0:
			arr.append(m % 10)
			m += c
			d -= 1
		ans = sum(arr)
	print(ans)


import sys
T = int(input())
for x in range(T):
	tab = []
	somma = 0
	(n, m) = map(int, input().split())
	somma = 0
	for y in range(1, 11):
		c = m * y
		c = str(c)
		if int(c[-1]) not in tab:
			if int(c) < 10:
				c = int(c)
				somma = somma + c
				tab.append(c)
			else:
				c = int(c[-1])
				somma = somma + c
				tab.append(c)
		else:
			break
	R = n // m
	r = R // len(tab)
	q = R % len(tab)
	risultato = somma * r
	for y in range(q):
		risultato += tab[y]
	print(risultato)


t = int(input())
for _ in range(t):
	tmp = input().split()
	n = int(tmp[0])
	m = int(tmp[1])
	pattern = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
	lastm = m % 10
	count = n // m
	print(sum(pattern[lastm]) * (count // len(pattern[lastm])) + sum(pattern[lastm][:count % len(pattern[lastm])]))


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	mods = [m % 10]
	nex = (mods[-1] + m) % 10
	while nex != mods[0]:
		mods.append(nex)
		nex = (mods[-1] + m) % 10
	modsums = [0]
	for i in mods:
		modsums.append(modsums[-1] + i)
	res = n // m // len(mods) * modsums[len(mods)]
	res += modsums[n // m % len(mods)]
	print(res)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	s = []
	tots = 0
	if n < m:
		print(0)
	elif n == m:
		print(n % 10)
	else:
		for j in range(1, 11):
			s.append(m * j % 10)
			tots += m * j % 10
		times = n // m // 10
		rem = n // m % 10
		ans = tots * times + sum(s[:rem])
		print(ans)


q = int(input())
for i in range(q):
	myl = input().split(' ')
	n = int(myl[0])
	m = int(myl[1])
	d = n // m
	s = 0
	for i in range(1, 11):
		s = s + m * i % 10
	s = d // 10 * s
	for i in range(1, d % 10 + 1):
		s += m * i % 10
	print(s)


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)


q = int(input())
for i in range(q):
	(n, m) = [int(x) for x in input().split()]
	digs = n // m
	unit = m % 10
	cycle = 0
	sum = 0
	if unit in [1, 3, 7, 9]:
		cycle = 10
		sum = 45
	elif unit in [2, 4, 6, 8]:
		cycle = 5
		sum = 20
	elif unit == 5:
		cycle = 2
		sum = 5
	else:
		cycle = 1
		sum = 0
	ans = sum * (digs // cycle)
	digs = digs % cycle
	p = m
	for j in range(digs):
		ans = ans + p % 10
		p = p + m
	print(ans)


from sys import stdin
q = int(input())
for _ in range(q):
	(n, m) = list(map(int, stdin.readline().rstrip().split(' ')))
	prefixSum = [0] * 10
	answer = 0
	for i in range(9):
		prefixSum[i + 1] = prefixSum[i] + m * (i + 1) % 10
	q = n // m
	r = q % 10
	q = q // 10
	answer += prefixSum[-1] * q
	answer += prefixSum[r]
	print(answer)


n = int(input())
for x in range(n):
	(page, div) = list(map(int, input().split()))
	initial = 1
	value = 0
	count = 0
	dic = {}
	dic[0] = 0
	while True:
		current = div * initial
		value += int(str(current)[-1])
		dic[initial] = value
		initial += 1
		count += 1
		if str(current)[-1] == '0':
			break
	if current < page:
		dam = page // current
		value *= int(dam)
		lam = page - current * dam
		init = int(lam // div)
		value += dic[init]
		print(value)
	elif div > page:
		print(0)
	else:
		initial = 1
		value = 5 - 5
		while True:
			current = div * initial
			value += int(str(current)[-1])
			dic[initial] = value
			initial += 1
			count += 1
			if div * initial > page:
				break
		print(value)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	i = 1
	while int(str(m * i)[-1]) != 0:
		arr.append(int(str(m * i)[-1]))
		i += 1
	arr.append(0)
	s = sum(arr)
	summ = 0
	x = len(arr) * m
	v = n // x
	summ += s * v
	y = n - x * v
	c = y // m
	summ += sum(arr[:c])
	print(summ)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	lst = []
	tmp = 0
	for i in range(10):
		tmp += m
		lst.append(tmp % 10)
	s = sum(lst)
	ans = s * (n // (m * 10))
	trm = n % (m * 10)
	trm //= m
	tmp = 0
	for i in range(trm):
		tmp += m
		ans += tmp % 10
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	arr = []
	if m > n:
		ans = 0
	else:
		for i in range(1, 11):
			arr.append(int(str(i * m)[-1]))
		x = n // (10 * m)
		y = n % (10 * m)
		s = sum(arr)
		ans = x * s
		i = 1
		p = 0
		if y > 0:
			while i * m <= y:
				p = i
				i = i + 1
		ans = sum(arr[0:p]) + ans
	print(ans)


k = int(input())
c = list()
for j in range(k):
	(n, m) = map(int, input().split())
	x = n // m
	a = list()
	m %= 10
	mm = m
	a.append(m)
	m += mm
	m %= 10
	while a[0] != m:
		a.append(m)
		m += mm
		m %= 10
	res = x // len(a)
	c.append(res * sum(a) + sum(a[0:x - res * len(a)]))
for i in range(k):
	print(c[i])


t = int(input())
while t > 0:
	(n, m) = [int(i) for i in input().split()]
	las = m % 10
	if n < m:
		print(0)
	elif las == 0:
		print(0)
	else:
		div = n // m
		lastdiv = div % 10
		fd = (div - lastdiv) // 10
		summ = 0
		count = lastdiv
		totalsum = 0
		it = 0
		for i in range(las, las * 10 + 1, las):
			if it < count:
				summ += i % 10
				it += 1
			totalsum += i % 10
		print(fd * totalsum + summ)
	t -= 1


q = int(input())
for i in range(q):
	(n, m) = list(map(int, input().split(' ')))
	cnt = 1
	sum1 = 0
	if n % m == 0:
		num = n // m
	else:
		num = (n - n % m) // m
	if num > 10:
		sum3 = 0
		rem = num % 10
		for i in range(10):
			d = m * i % 10
			sum1 = sum1 + d
			if i <= rem:
				sum3 = sum3 + d
		sum2 = (num - rem) // 10
		sum4 = sum2 * sum1 + sum3
		print(sum4)
	else:
		for i in range(num + 1):
			d = m * i % 10
			sum1 = sum1 + d
		print(sum1)


def practice(n, m):
	if m > n:
		return 0
	elif n <= 10:
		count = 0
		no = 1
		i = 1
		while True:
			no = m * i
			i = i + 1
			if no > n:
				break
			count += int(str(no)[-1])
		return count
	else:
		count = []
		no = 1
		i = 1
		while True:
			no = m * i
			i = i + 1
			if i > 10:
				break
			count.append(int(str(no)[-1]))
		y = n // m
		x = y // 10
		a = sum(count) * x
		b = sum(count[:y - 10 * x])
		ans = a + b
		return ans
n = int(input())
ans = []
for x in range(n):
	arr = [int(i) for i in input().split()]
	value = practice(arr[0], arr[1])
	ans.append(value)
for a in ans:
	print(a)


from collections import defaultdict as DD
from bisect import bisect_left as BL
from bisect import bisect_right as BR
from itertools import combinations as IC
from itertools import permutations as IP
from random import randint as RI
import sys
MOD = pow(10, 9) + 7

def IN(f=0):
	if f == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
tc = int(input())
for _ in range(tc):
	(n, m) = IN()
	a = []
	p = int(str(m)[-1])
	for i in range(1, 11):
		a.append(int(str(i * p)[-1]))
	n = n // m
	f = n // 10
	ans = sum(a) * f
	ans += sum(a[:n % 10])
	print(ans)


for case in range(int(input())):
	(n, m) = list(map(int, input().split()))
	use = [False for i in range(10)]
	tmp = m
	cnt = 0
	rem = []
	while not use[tmp % 10]:
		use[tmp % 10] = True
		cnt += 1
		rem.append(tmp % 10)
		tmp += m
	k = n // m
	print(k // cnt * sum(rem) + sum(rem[:k % cnt]))


q = int(input())
for qu in range(q):
	(n, m) = map(int, input().split())
	su = 0
	for i in range(1, 11):
		su += m * i % 10
	cale = n // m // 10 * su
	for i in range(1, n // m - 10 * (n // m // 10) + 1):
		cale += i * m % 10
	print(cale)


I = input
for _ in range(int(I())):
	(n, m) = map(int, I().split())
	ord = dict()
	for i in range(1, 11):
		a = str(m * i)
		a = a[len(a) - 1]
		ord[int(a)] = 0
	ord = list(ord)
	l = len(ord)
	x = n // m
	if x % l == 0:
		print(sum(ord) * (x // l))
	else:
		a = sum(ord) * (x // l)
		a += sum(list(ord)[:x % l])
		print(a)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	t = n // m // 10
	rem = n // m % 10
	vals = {}
	cumi = 0
	ans = 0
	if m > n:
		print('0')
	elif m == n:
		print(n % 10)
	elif t > 0:
		for i in range(1, 11):
			cumi += i * m % 10
			vals[i] = i * m % 10
		ans = cumi * t
		for i in range(1, rem + 1):
			ans += vals[i]
		print(ans)
	else:
		for i in range(1, n // m + 1):
			ans += i * m % 10
		print(ans)


for _ in range(int(input())):
	d = [int(i) for i in input().split()]
	total = d[0] // d[1]
	t = total // 10
	x = total - t * 10
	count = 0
	k = 1
	g = 0
	while k <= 10:
		count += k * d[1] % 10
		if x >= k:
			g = g + k * d[1] % 10
		k = k + 1
	print(count * t + g)


a = int(input())
for i in range(a):
	(m, n) = map(int, input().split())
	m = m // n
	t = n % 10
	r = m // 10
	if t == 0:
		r *= 0
	elif t == 5:
		r *= 25
	elif t % 2 == 0:
		r *= 40
	else:
		r *= 45
	for j in range(m % 10):
		r += t * (j + 1) % 10
	print(str(r))


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().strip())
for _ in range(q):
	addUp = 0
	store = []
	(n, m) = map(int, input().strip().split())
	if m % 10 == 0:
		result = 0
	if m % 10 == 1:
		a1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
		b1 = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]
		d1 = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210]
		e1 = [26, 52, 78, 104, 130]
		bb = 10 + 100 * (m // 10)
		aa = n // bb * bb
		result = sum([1, 2, 3, 4, 5, 6, 7, 8, 9]) * (n // bb) + sum(a1[:int((n - aa) / bb * 10)])
	if m % 10 == 2:
		a1 = [2, 4, 6, 8, 0]
		b1 = [12, 24, 36, 48, 60]
		d1 = [22, 44, 66, 88, 100]
		e1 = [32, 64, 96, 128, 160]
		c1 = 10 + m // 10 * 50
		result = 20 * (n // c1) + sum(a1[:int(n % c1 / c1 * 10 / 2)])
	if m % 10 == 3:
		a1 = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
		cc = 30 + 100 * (m // 10)
		dd = n // cc * cc
		result = sum(a1) * (n // cc) + sum(a1[:int((n - dd) / cc * 10)])
	if m % 10 == 4:
		c1 = 20 + m // 10 * 50
		a1 = [4, 8, 2, 6, 0]
		result = 20 * (n // c1) + sum(a1[:int(n % c1 / c1 * 10 / 2)])
	if m % 10 == 5:
		if 0 <= n % (m * 2) <= m // 10 * 10 + 4:
			a = n - n % (m * 2)
			resu = int(a / m / 2)
		else:
			a = n + (m - n % (m * 2))
			resu = int((a - m) / m / 2) + 1
		result = resu * 5
	if m % 10 == 6:
		c1 = 30 + m // 10 * 50
		a1 = [6, 2, 8, 4, 0]
		b1 = [6, 12, 18, 24, 30]
		d1 = [16, 32, 48, 64, 80]
		e1 = [26, 52, 78, 104, 130]
		result = 20 * (n // c1) + sum(a1[:int(n % c1 / c1 * 10 / 2)])
	if m % 10 == 7:
		a1 = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
		b1 = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
		d1 = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170]
		e1 = [27, 54, 81, 108, 135, 162, 189, 216, 243, 270]
		cc = 70 + 100 * (m // 10)
		dd = n // cc * cc
		result = sum(a1) * (n // cc) + sum(a1[:int((n - dd) / cc * 10)])
	if m % 10 == 8:
		c1 = 40 + m // 10 * 50
		a1 = [8, 6, 4, 2, 0]
		b1 = [8, 16, 24, 32, 40]
		d1 = [18, 36, 54, 72, 90]
		e1 = [28, 56, 84, 112, 140]
		result = 20 * (n // c1) + sum(a1[:int(n % c1 / c1 * 10 / 2)])
	if m % 10 == 9:
		a1 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
		b1 = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]
		d1 = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190]
		e1 = [29, 58, 87, 116, 145, 174, 203, 232, 261, 290]
		bb = 90 + 100 * (m // 10)
		aa = n // bb * bb
		result = sum([1, 2, 3, 4, 5, 6, 7, 8, 9]) * (n // bb) + sum(a1[:int((n - aa) / bb * 10)])
	print(result)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().strip().split())
	m_ = int(str(m)[-1])
	q = n // m
	pattern = []
	for i in range(1, 10):
		ele = m_ * i
		if ele % 10 != 0:
			pattern.append(int(str(ele)[-1]))
		else:
			break
	pattern.append(0)
	sm = sum(pattern)
	res = sm * (q // len(pattern))
	rem = q % len(pattern)
	for i in range(rem):
		res += pattern[i]
	print(res)


queries = int(input())
for i in range(queries):
	(total_pages, m) = [int(i) for i in input().split()]
	seq_last_digits = []
	i = m
	sum_seq = 0
	while True:
		last_digit = i % 10
		seq_last_digits.append(last_digit)
		sum_seq += last_digit
		if last_digit == 0:
			break
		else:
			i += m
	qtd_nums_to_sum = total_pages // m
	mult = qtd_nums_to_sum // len(seq_last_digits)
	rest = qtd_nums_to_sum % len(seq_last_digits)
	output = mult * sum_seq
	for i in range(rest):
		output += seq_last_digits[i]
	print(output)


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)
input = sys.stdin.readline

def main():
	q = int(input())
	for _ in range(q):
		(n, m) = map(int, input().split())
		nums = n // m
		ans = 0
		set = nums // 10
		nums = nums - set * 10
		m = int(str(m)[-1])
		if set:
			sm = 0
			tmp = m
			for _ in range(10):
				sm += tmp
				tmp += m
				tmp = int(str(tmp)[-1])
			ans = sm * set
		sm = 0
		tmp = m
		for _ in range(nums):
			sm += tmp
			tmp += m
			tmp = int(str(tmp)[-1])
		ans += sm
		print(ans)
main()


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	ans = 0
	if n > 10:
		per = 5 if m % 2 == 0 else 10
		count = n // m
		last = m % 10
		ch = last
		circle = []
		for i in range(per):
			circle.append(ch % 10)
			ch += last
		s = sum(circle)
		ans += count // per * s
		pos = count % per
		for i in range(pos):
			ans += circle[i]
	else:
		for i in range(n + 1):
			if i % m == 0:
				ans += i % 10
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if m > n:
		ans = 0
	elif (n - n % m) // m < 10:
		ans = 0
		k = n - n % m
		x = k // m
		for i in range(1, x + 1):
			ans += i * m % 10
	else:
		ans = 0
		z = 1
		sum = 0
		while z < 11:
			sum += z * m % 10
			z += 1
		k = n - n % m
		x = k // m
		s = x % 10
		x = x - s
		x = x // 10
		ans += sum * x
		for i in range(1, s + 1):
			ans += m * i % 10
	print(ans)


for u in range(int(input())):
	(n, k) = map(int, input().split())
	if n < k:
		print(0)
	else:
		l = []
		for i in range(1, 11):
			if k * i % 10 in l:
				break
			l.append(k * i % 10)
		s = sum(l)
		x = n // k
		r = x // len(l) * s + sum(l[:x % len(l)])
		print(r)


import math

def god(n, k):
	s = 0
	if k == 0:
		return 0
	if k == 1:
		return n % 10
	s += n % 10
	if k == 2:
		return s + 2 * n % 10
	s += 2 * n % 10
	if k == 3:
		return s + 3 * n % 10
	s += 3 * n % 10
	if k == 4:
		return s + 4 * n % 10
	s += 4 * n % 10
	if k == 5:
		return s + 5 * n % 10
	s += 5 * n % 10
	if k == 6:
		return s + 6 * n % 10
	s += 6 * n % 10
	if k == 7:
		return s + 7 * n % 10
	s += 7 * n % 10
	if k == 8:
		return s + 8 * n % 10
	s += 8 * n % 10
	if k == 9:
		return s + 9 * n % 10
	s += 9 * n % 10
for i in range(int(input())):
	(n, m) = map(int, input().split())
	c = n // m
	g = c // 10
	q = c % 10
	print(g * god(m, 9) + god(m, q))


import math
q = int(input())
for z in range(q):
	(n, m) = map(int, input().split())
	t = m % 10
	pat = [t]
	if t > 0:
		for i in range(t + t, t * 11 + 1, t):
			if i % 10 == t:
				break
			pat.append(i % 10)
	print(sum(pat) * int(math.floor(n / m / len(pat))) + sum(pat[:n // m % len(pat)]))


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	for i in range(1, 11):
		if m * i % 10 == 0:
			temp = i
			break
	s = 0
	for i in range(1, temp + 1):
		s += m * i % 10
	temp2 = n // (temp * m)
	S = temp2 * s
	n -= temp * m * temp2
	x = n // m
	for i in range(1, x + 1):
		S += m * i % 10
	print(S)


t = int(input())
for j in range(t):
	(n, m) = map(int, input().split())
	l1 = []
	x = m % 10
	l1.append(x)
	for i in range(2, 10000000):
		x1 = x * i % 10
		if x1 == l1[0]:
			break
		l1.append(x1)
	a = n // m
	ans = sum(l1) * (a // len(l1))
	r = a % len(l1)
	if r != 0:
		ans += sum(l1[:r])
	print(ans)


q = int(input())
while q:
	q -= 1
	(n, m) = map(int, input().split())
	x1 = n // m
	x2 = x1 % 10
	s = 0
	x1 = x1 // 10
	nel = m % 10
	if m % 10 == 0:
		print(0)
		continue
	if m % 10 == 5:
		s += x1 * 25
		for i in range(1, x2 + 1):
			s += m * i % 10
		print(s)
		continue
	if nel % 2 == 0:
		s += x1 * 40
		for i in range(1, x2 + 1):
			s += m * i % 10
	if nel % 2 != 0:
		s += x1 * 45
		for i in range(1, x2 + 1):
			s += m * i % 10
	print(int(s))


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


def get_cycle(digit):
	res = [digit]
	while len(res) == 1 or res[-1] != digit:
		res.append((res[-1] + digit) % 10)
	return res[:-1]

def solve(n, m):
	relevant = m % 10
	if relevant == 0:
		return 0
	n_times = n // m
	cycle = get_cycle(relevant)
	cycles = n_times // len(cycle)
	left = n_times % len(cycle)
	return sum(cycle) * cycles + sum(cycle[:left])
cases = int(input())
for i in range(cases):
	(n, m) = [int(i) for i in input().split()]
	print(solve(n, m))


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	s = 0
	for i in range(1, 11):
		s += m * i % 10
	k = n // (m * 10)
	s = s * k
	n = n % (m * 10)
	c = m
	while c <= n:
		s += c % 10
		c += m
	print(s)


q = int(input())
for i in range(0, q):
	a = list(map(int, input().split()))
	if a[0] < a[1]:
		print(0)
	else:
		k = a[0] // a[1]
		ans = int(0)
		b = [0, 0, 0, 0, 0, 0, 0, 0, 0]
		while k % 10 != 0:
			b[k % 10 - 1] += 1
			k -= 1
		k = k // 10
		for i in range(0, 9):
			ans += (k + b[i]) * (a[1] % 10 * (i + 1) % 10)
		print(ans)


q = int(input())
tenlist = [pow(10, i) for i in range(20)]

def get(u):
	sum = 0
	kk = u
	for i in range(10):
		sum += int(str(kk)[-1])
		kk += u
	return sum
for i in range(q):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	div = n // m
	wsum = get(m)
	sum = 0
	k = len(str(div)) - 2
	for c in str(div):
		if k < 0:
			break
		sum += int(c) * tenlist[k] * wsum
		k -= 1
	for k in range(int(str(div)[-1])):
		sum += int(str(m * (k + 1))[-1])
	print(sum)


def arr(m):
	l = list()
	for i in range(1, 11):
		l.append(m * i % 10)
	return l
t = int(input())
for _ in range(0, t):
	(n, m) = list(map(int, input().split()))
	l = arr(m % 10)
	s = sum(l)
	a = n // m
	ans = s * (a // 10) + sum(l[0:a % 10])
	print(ans)


for case in range(int(input())):
	(n, m) = map(int, input().split())
	digits = [0 for i in range(10)]
	n = n // m
	for i in range(10):
		digits[i] = (i + 1) * m % 10
	summ = 0
	for i in range(n % 10):
		summ += digits[i]
	print(summ + n // 10 * sum(digits))


q = int(input())
for i in range(q):
	(n, m) = [int(x) for x in input().split()]
	v = n // m
	p = sum([(c + 1) * m % 10 for c in range(10)])
	a = v // 10 * p
	last = sum([(c + 1) * m % 10 for c in range(v % 10)])
	print(a + last)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = n // m
	b = {1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 2: [2, 4, 6, 8, 0], 3: [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], 4: [4, 8, 2, 6, 0], 5: [5, 0], 6: [6, 2, 8, 4, 0], 7: [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], 8: [8, 6, 4, 2, 0], 9: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0: [0]}
	if m % 10 == 0:
		print(0)
	elif m % 2 == 0:
		print(sum(b[m % 10]) * (a // 5) + sum(b[m % 10][:a % 5]))
	elif m % 5 == 0:
		print(sum(b[m % 10]) * (a // 2) + sum(b[m % 10][:a % 2]))
	else:
		print(sum(b[m % 10]) * (a // 10) + sum(b[m % 10][:a % 10]))


def readInts():
	return [int(x) for x in input().split()]
Q = int(input())
for q in range(Q):
	[N, M] = readInts()
	k = N // M
	digits = [0 for i in range(10)]
	for i in range(10):
		digits[i] = (i + 1) * M % 10
	result = 0
	for i in range(k % 10):
		result += digits[i]
	print(result + k // 10 * sum(digits))


t = int(input())
loi = []
for k in range(t):
	counter1 = 0
	string1 = list(input())
	placeholdern = ''
	placeholderb = ''
	for p in string1:
		if p != ' ' and counter1 == 0:
			placeholdern = placeholdern + p
		elif p != ' ' and counter1 == 1:
			placeholderb = placeholderb + p
		elif p == ' ':
			counter1 = counter1 + 1
	infotemplist = []
	infotemplist.append(int(placeholdern))
	infotemplist.append(int(placeholderb))
	loi.append(infotemplist)
for k in range(t):
	n = loi[k][0]
	m = loi[k][1]
	req = 0
	if m % 2 == 0:
		if m % 10 == 0:
			verywell = n // m
			a = verywell // 10
			b = verywell % 10
			req = a * 0 + sum([int(str(m * x)[-1]) for x in range(1, b + 1)])
		else:
			verywell = n // m
			a = verywell // 10
			b = verywell % 10
			req = a * 40 + sum([int(str(m * x)[-1]) for x in range(1, b + 1)])
	elif m % 5 == 0:
		verywell = n // m
		a = verywell // 10
		b = verywell % 10
		req = a * 25 + sum([int(str(m * x)[-1]) for x in range(1, b + 1)])
	else:
		verywell = n // m
		a = verywell // 10
		b = verywell % 10
		req = a * 45 + sum([int(str(m * x)[-1]) for x in range(1, b + 1)])
	print(req)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n <= m * 10:
		x = m
		sum = 0
		while x <= n:
			sum += x % 10
			x += m
		print(sum)
	else:
		sum = 0
		x = m
		while x <= 10 * m:
			sum += x % 10
			x += m
		x = 10 * m
		mul = n // x
		sum = sum * mul
		x = x * mul
		while x <= n:
			sum += x % 10
			x += m
		print(sum)


d = (0, 45, 40, 45, 40, 25, 40, 45, 40, 45)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	summ = n // (m * 10) * d[m % 10]
	r = n % (m * 10)
	t = 0
	while t + m <= r:
		t += m
		summ += t % 10
	print(summ)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	k = n // m
	l = k // 10
	s = k % 10
	t9 = 0
	prev = 0
	ts = 0
	for j in range(9):
		prev += m
		prev %= 10
		t9 += prev
		if j == s - 1:
			ts = t9
	print(l * t9 + ts)


from sys import stdin
from itertools import accumulate

def main():
	tt = [tuple(accumulate((x * m % 10 for x in range(10)))) for m in range(10)]
	(_, *l) = stdin.read().splitlines()
	for (i, s) in enumerate(l):
		(n, m) = map(int, s.split())
		t = tt[m % 10]
		(n, m) = divmod(n // m, 10)
		l[i] = str(n * t[9] + t[m])
	print('\n'.join(l))
main()


import unittest
LOOP_TABLE = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]

def solve(n, m):
	if n < m:
		return 0
	ans = 0
	final_digit = m % 10
	if final_digit == 0:
		return 0
	tab = LOOP_TABLE[final_digit]
	ans = n // m // len(tab) * sum(tab)
	ans += sum(tab[:n // m % len(tab)])
	return ans

class TestCase(unittest.TestCase):

	def test1(self):
		self.assertEqual(solve(1, 1), 1)

	def test2(self):
		self.assertEqual(solve(10, 1), 45)

	def test3(self):
		self.assertEqual(solve(100, 3), 153)

	def test4(self):
		self.assertEqual(solve(1024, 14), 294)

	def test5(self):
		self.assertEqual(solve(998244353, 1337), 3359835)

	def test6(self):
		self.assertEqual(solve(123, 144), 0)

	def test7(self):
		self.assertEqual(solve(1234312817382646, 13), 427262129093995)
q = int(input())
for _ in range(0, q):
	(n, m) = [int(i) for i in input().split()]
	print(solve(n, m))


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


import sys
from collections import defaultdict
q = int(sys.stdin.readline())
for _ in range(q):
	(n, m) = map(int, sys.stdin.readline().split())
	l = []
	for i in range(1, 10):
		l.append(m * i % 10)
	l.append(0)
	if n < m:
		print(0)
		continue
	x = n // m
	y = x // 10
	z = x % 10
	s = sum(l)
	ans = s * y
	for i in range(z):
		ans += l[i]
	print(ans)


k = int(input())
for _ in range(k):
	(n, m) = list(map(int, input().split(' ')))
	div = n // m
	dig = m % 10
	mod = div % 10
	multi = 0
	if dig == 0:
		multi = 0
	elif dig == 5:
		multi = 25
	elif dig % 2 == 0:
		multi = 40
	elif dig % 2 == 1:
		multi = 45
	s = div // 10 * multi
	if mod:
		for i in range(1, mod + 1):
			s += i * dig % 10
	print(int(s))


from math import ceil, log, floor, sqrt

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def find_product(n, m, arr):
	product = 1
	if n <= m:
		for i in range(n):
			for j in range(i + 1, n):
				product = product * abs(arr[i] - arr[j]) % m
		return product
	return 0

def count_tables(l):
	count = 0
	l.sort()
	a = l[1] - l[0]
	b = l[2] - l[0]
	if a % 3 > 0 and a % 3 + (b - (a - a % 3)) >= 3:
		count += 1
	count += l[0] + 2 * a // 3
	return int(min(sum(l) / 3, l[0] + l[1]))

def find_possible_weight(W, arr):
	w = 0
	for i in range(8, 0, -1):
		count = min(arr[i - 1], W // i)
		w += count * i
		W -= count * i
	return w

def find_divisor(a):
	divisors = []
	for i in range(2, min(a, ceil(sqrt(a)) + 1)):
		if a % i == 0:
			if a / i == i:
				divisors.append(i)
			else:
				divisors.append(i)
				divisors.append(a / i)
	if len(divisors) == 0:
		return -1
	return int(min(divisors))

def find_sum(n, m):
	prod = []
	(total, res, index) = (0, 0, 0)
	for i in range(1, 10):
		prod.append(m * i % 10)
	total = sum(prod)
	res += n // (10 * m) * total
	n -= n // (10 * m) * (10 * m)
	count = n // m
	while count:
		res += prod[index]
		count -= 1
		index += 1
	return res
t = 1
t = int(input())
while t:
	t = t - 1
	(n, m) = map(int, input().split())
	print(find_sum(n, m))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	circle = []
	current = m
	while current % 10 not in circle:
		circle.append(current % 10)
		current += m
	steps = n // (current - m)
	n -= steps * (current - m)
	total = sum(circle) * steps
	additional = sum((x % 10 for x in range(m, n + 1, m)))
	print(total + additional)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [0] * 11
	for i in range(1, 11):
		a[i] = m * i % 10
	s = sum(a)
	d = n // m // 10
	g = n // m % 10
	k = 0
	for i in range(1, g + 1):
		k += a[i]
	print(s * d + k)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	if m == 1:
		if n == 1:
			ans = 1
		else:
			ans = 45 * (n // 10)
			if n % 10 != 0:
				for i in range(1, n % 10 + 1):
					ans += i
	elif m > n or m == 10:
		ans = 0
	else:
		if m % 2 == 1:
			k = 10
		else:
			k = 5
		for i in range(k):
			g = (i + 1) * m
			g %= 10
			ans += g * (n // (m * k))
		for i in range(m, n % (m * k) + 1, m):
			ans += i % 10
	print(ans)


a = [[0] * 11] * 11
b = [0] * 11
for i in range(1, 11):
	for j in range(1, 11):
		a[i][j] = i * j % 10
		b[i] += a[i][j]
for _ in range(int(input())):
	c = 0
	(m, n) = map(int, input().split())
	st = str(n)
	la = int(st[-1])
	s = m // n // 10
	mod = m // n % 10
	c += s * b[la]
	for i in range(1, mod + 1):
		c += n * i % 10
	print(c)


q = int(input())
while q:
	(n, m) = [int(x) for x in input().split()]
	pattern = []
	i = m
	while i % 10 not in pattern:
		pattern.append(i % 10)
		i += m
	a = n // m
	answer = sum(pattern) * (a // len(pattern))
	a %= len(pattern)
	i = 0
	while a:
		answer += pattern[i % len(pattern)]
		i += 1
		a -= 1
	print(int(answer))
	q -= 1


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)


import math
tst = int(input())
for _ in range(tst):
	(b, a) = 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)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	t = 0
	j = 0
	for i in range(1, 11):
		t += m * i % 10
	n = n - n % m
	n1 = n - n % (m * 10)
	t1 = n1 // (m * 10)
	j = t1 * t
	k = n % (m * 10)
	for i in range(1, k // m + 1):
		j += m * i % 10
	print(j)


import sys
import math
import bisect

def solve(n, m):
	cnt = n // m
	A = [m % 10]
	while True:
		val = (A[-1] + m) % 10
		if val in A:
			break
		A.append(val)
	ans = 0
	if cnt >= len(A):
		ans += cnt // len(A) * sum(A)
	for i in range(cnt % len(A)):
		ans += A[i]
	return ans

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		print(solve(n, m))
main()


import sys
import math
from collections import defaultdict
from collections import Counter
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	a = []
	a.append(0)
	c = 0
	for i in range(m, n + 1, m):
		if c == 10:
			break
		a.append(a[c] + i % 10)
		c += 1
	t1 = n // (m * 10)
	ans = a[c] * t1
	t2 = (n - t1 * m * 10) // m
	ans += a[t2]
	print(ans)


q = int(input())
anss = []
for i in range(q):
	(n, m) = map(int, input().split())
	k = m % 10
	ans = 0
	if k:
		r = [k]
		while (r[-1] + k) % 10 not in r:
			r.append((r[-1] + k) % 10)
		l = n // m
		len_r = len(r)
		for (j, a) in enumerate(r):
			ans += a * (l // len_r + int(j < l % len_r))
	anss.append(ans)
print(*anss, sep='\n')


from math import ceil
queries = int(input())
for q in range(queries):
	(n, m) = list(map(int, input().split()))
	div = n // m
	div_recur = div // 10
	div_remain = div % 10
	recur = 0
	if div_recur:
		for j in range(10):
			recur += j * m % 10
	remain = 0
	for j in range(div_remain + 1):
		remain += j * m % 10
	mysum = remain + recur * div_recur
	print(mysum)


for q in range(int(input())):
	(n, m) = map(int, input().split())
	x = n // m
	rem = x % 10
	quo = x // 10
	arr = [0] * 10
	for i in range(1, 11):
		arr[i - 1] = m * i % 10
	s1 = quo * sum(arr) + sum(arr[:rem])
	print(s1)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	s = 0
	els = []
	for i in range(1, 11):
		v = i * m
		if v <= n:
			vv = v % 10
			s += vv
			els.append(vv)
		else:
			print(s)
			break
	else:
		times = n // m // 10
		sub = n // m % 10
		print(times * s + sum(els[:sub]))


t = int(input())
for u in range(t):
	(n, m) = input().split(' ')
	(n, m) = (int(n), int(m))
	x = n // m
	a = 0
	if m % 10 % 2 == 0 and m % 10 != 0:
		a = 40 * (x // 10)
	elif m % 10 == 5:
		a = 25 * (x // 10)
	elif m % 10 % 2 != 0:
		a = 45 * (x // 10)
	x = x % 10
	m = m % 10
	for i in range(1, x + 1):
		a += m * i % 10
	print(a)


def ultAlg(n):
	strN = str(n)
	return int(strN[-1])
q = int(input())
for i in range(q):
	input1 = input().split()
	n = int(input1[0])
	m = int(input1[1])
	mUltimo = int(input1[1][-1])
	somaTotal = 0
	divisao = n // (m * 10)
	if mUltimo == 0:
		somaTotal = 0
	elif mUltimo == 5:
		somaTotal = 25 * divisao
	elif mUltimo % 2 == 0:
		somaTotal = 40 * divisao
	else:
		somaTotal = 45 * divisao
	nDivisao = divisao * m * 10
	nDivisao += m
	while n >= nDivisao:
		somaTotal += ultAlg(nDivisao)
		nDivisao += m
	print(somaTotal)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(1, 11):
		c = str(m * i)
		st = c[-1]
		l.append(int(st))
	sm = sum(l)
	xx = n // m
	x = xx // 10
	y = xx % 10
	ans = sm * x
	ans += sum(l[:y])
	print(ans)


t = int(input())
x1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
x2 = [2, 4, 6, 8, 0]
x3 = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
x4 = [4, 8, 2, 6, 0]
x5 = [5, 0]
x6 = [6, 2, 8, 4, 0]
x7 = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
x8 = [8, 6, 4, 2, 0]
x9 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
for i in range(t):
	(n, m) = map(int, input().split())
	no = n // m
	l = m % 10
	if l == 1:
		p = no // 10
		total = sum(x1) * p + sum(x1[:no - p * 10])
		print(total)
	elif l == 2:
		p = no // 5
		total = sum(x2) * p + sum(x2[:no - p * 5])
		print(total)
	elif l == 3:
		p = no // 10
		total = sum(x3) * p + sum(x3[:no - p * 10])
		print(total)
	elif l == 4:
		p = no // 5
		total = sum(x4) * p + sum(x4[:no - p * 5])
		print(total)
	elif l == 5:
		p = no // 2
		total = sum(x5) * p + sum(x5[:no - p * 2])
		print(total)
	elif l == 6:
		p = no // 5
		total = sum(x6) * p + sum(x6[:no - p * 5])
		print(total)
	elif l == 7:
		p = no // 10
		total = sum(x7) * p + sum(x7[:no - p * 10])
		print(total)
	elif l == 8:
		p = no // 5
		total = sum(x8) * p + sum(x8[:no - p * 5])
		print(total)
	elif l == 9:
		p = no // 10
		total = sum(x9) * p + sum(x9[:no - p * 10])
		print(total)
	else:
		print(0)


s = []
for i in range(int(input())):
	(n, m) = map(int, input().split())
	d = n // m // 10
	b = n // m % 10
	sum1 = 0
	for i in range(1, 11):
		sum1 += m * i % 10
	y = sum1 * d
	sum2 = 0
	for i in range(1, b + 1):
		sum2 += m * i % 10
	s.append(y + sum2)
for i in range(len(s)):
	print(s[i])


n = int(input())
lista = [[0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 4, 6, 8, 0], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [4, 8, 2, 6, 0], [5, 0], [6, 2, 8, 4, 0], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
soma = [[0], [sum(lista[1])], [sum(lista[2])], [sum(lista[3])], [sum(lista[4])], [sum(lista[5])], [sum(lista[6])], [sum(lista[7])], [sum(lista[8])], [sum(lista[9])]]
while n:
	res = 0
	(x, y) = map(int, input().split())
	div = x // y
	y = str(y)
	ultimoD = y[len(y) - 1]
	ultimoD = int(ultimoD)
	y = int(y)
	nCiclo = div // len(lista[ultimoD])
	resto = div % len(lista[ultimoD])
	res += nCiclo * soma[ultimoD][0]
	for i in range(resto):
		res += lista[ultimoD][i]
	print(res)
	n -= 1


t = int(input())

def nums(n):
	s = [n]
	for i in range(2 * n, 100, n):
		a = i % 10
		if a in s:
			break
		s.append(a)
	return s
for q in range(t):
	(n, m) = map(int, input().split())
	if m % 10 == 0:
		print(0)
		continue
	s = nums(m % 10)
	ss = 0
	for i in range(len(s)):
		ss += s[i]
	p = n // m
	q = p // len(s)
	ans = q * ss
	q = p % len(s)
	for i in range(q):
		ans += s[i]
	print(ans)


q = int(input())
period = [[], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8], [0, 3, 6, 9, 2, 5, 8, 1, 4, 7], [0, 4, 8, 2, 6], [0, 5], [0, 6, 2, 8, 4], [0, 7, 4, 1, 8, 5, 2, 9, 6, 3], [0, 8, 6, 4, 2], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]]
psum = [sum(x) for x in period]
for i in range(q):
	(n, m) = (int(x) for x in input().split())
	a = m % 10
	if a == 0:
		print('0')
	else:
		b = n // m
		dm = divmod(b, len(period[a]))
		print(psum[a] * dm[0] + sum(period[a][:dm[1] + 1]))


from sys import stdin
q = int(stdin.readline().strip())
for _ in range(q):
	(n, m) = [int(i) for i in stdin.readline().strip().split()]
	s = sum((i * m % 10 for i in range(1, 10)))
	q = n // (10 * m)
	r = q * s
	for p in range(10 * q * m, n + 1, m):
		r += p % 10
	print(r)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	if k > n or k % 10 == 0:
		print(0)
	elif k % 2 == 0:
		mul = int(n // k // 5)
		rem = int(n // k % 5)
		ans = mul * 20
		for i in range(1, rem + 1):
			ans = ans + int(k * i) % 10
		print(ans)
	elif k % 5 == 0:
		mul = n // k // 2 + int(n // k % 2)
		ans = mul * 5
		print(ans)
	else:
		mul = n // k // 10
		rem = int(n // k % 10)
		ans = mul * 45
		for i in range(1, rem + 1):
			ans = ans + int(k * i % 10)
		print(ans)
	t = t - 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	sm = 0
	lg = m * 10 if n >= m * 10 else n + 1
	for i in range(m, lg, m):
		sm += int(str(i)[-1])
	if n >= m * 10:
		bcha = n % lg
		sm *= n // lg
		for i in range(m, bcha + 1, m):
			sm += int(str(i)[-1])
	print(sm)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	k = n // m
	s = 0
	i = 1
	while i < 10:
		s += i * m % 10
		i += 1
	ans = k // 10 * s
	i = 1
	while i <= k % 10:
		ans += i * m % 10
		i += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = [int(i) for i in input().split(' ')]
	mod_m = m % 10
	sum = 0
	for i in range(1, 11):
		sum += mod_m * i % 10
	ans = n // m // 10 * sum
	mod = n // m % 10
	for i in range(1, mod + 1):
		ans += mod_m * i % 10
	print(ans)


mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	i = 0
	temp = 0
	while i < 10:
		temp += m
		ans += temp % 10
		i += 1
	ans = n // (m * 10) * ans
	i = 0
	temp = 0
	while i < n % (10 * m) // m:
		temp += m
		ans += temp % 10
		i += 1
	print(ans)


def make_ring(base):
	base %= 10
	ring = [base]
	while True:
		nxt = (ring[-1] + base) % 10
		if nxt in ring:
			break
		else:
			ring.append(nxt)
	return ring
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	k = n // m
	ring = make_ring(m)
	ln = len(ring)
	sm = sum(ring)
	main = k // ln
	rest = k % ln
	result = main * sm + sum(ring[0:rest])
	print(result)


q = int(input())
for _ in range(q):
	(n, m) = [int(x) for x in input().split()]
	t = m
	arr = []
	for _ in range(10):
		t += m
		t = t % 10
		arr.append(t)
	flr = n // m
	ans = flr // 10 * sum(arr)
	k = flr % 10
	for i in range(-1, k - 1):
		ans += arr[i]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	dic = [0] * 10
	i = 2
	a = []
	s = m % 10
	while dic[s] != 1:
		dic[s] = 1
		a.append(s)
		s = m * i % 10
		i += 1
	t = n // m
	ans = sum(a) * (t // len(a)) + sum(a[0:t % len(a)])
	print(ans)


import math
import sys
from heapq import heappop
from heapq import heappush
from heapq import heapify
from bisect import insort
from sys import stdin, stdout
from collections import defaultdict
inp = lambda : int(stdin.readline())
sip = lambda : input()
mulip = lambda : map(int, input().split())
lst = lambda : list(map(int, stdin.readline().split()))
slst = lambda : list(sip())
arr2d = lambda x: [[int(j) for j in input().split()] for i in range(x)]
odds = lambda l: len(list(filter(lambda x: x % 2 != 0, l)))
evens = lambda l: len(list(filter(lambda x: x % 2 == 0, l)))
mod = pow(10, 9) + 7
for _ in range(inp()):
	(n, m) = mulip()
	if m > n:
		print(0)
	else:
		term = n // m
		d = {}
		i = 1
		while m <= n:
			s = str(m * i)
			l = int(s[-1])
			if l not in d:
				d[l] = l
				i += 1
			else:
				break
		dlen = len(d)
		full_nd = term // dlen
		part_nd = term % dlen
		full_sum = full_nd * sum(d.values())
		dlist = list(d.values())
		part_sum = sum(dlist[:part_nd])
		print(full_sum + part_sum)


q = int(input())
result = []
for _ in range(q):
	(n, m) = tuple(map(int, input().split()))
	c = 0
	summ = 0
	k = n // m
	for i in range(10):
		summ += m * (i + 1) % 10
	summ *= k // 10
	for i in range(k % 10):
		summ += m * (i + 1) % 10
	result.append(str(summ))
print('\n'.join(result))


a = [0, 45, 40, 45, 40, 25, 40, 45, 40, 45]
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mm = m % 10
	quo = n // m
	qq1 = quo % 10
	qq2 = (quo - qq1) // 10
	sum = qq2 * a[mm]
	for i in range(1, qq1 + 1):
		sum += mm * i % 10
	print(int(sum))


import sys, heapq
num = {1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 2: [2, 4, 6, 8, 0], 3: [3, 6, 9, 2, 5, 8, 1, 4, 7, 0], 4: [4, 8, 2, 6, 0], 5: [5, 0], 6: [6, 2, 8, 4, 0], 7: [7, 4, 1, 8, 5, 2, 9, 6, 3, 0], 8: [8, 6, 4, 2, 0], 9: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0: [0]}
tc = int(sys.stdin.readline())
for _ in range(tc):
	(n, m) = map(int, sys.stdin.readline().split())
	size = n // m
	last = int(str(m)[-1])
	q = size // len(num[last])
	mid = q * sum(num[last])
	size %= len(num[last])
	left = 0
	for i in range(size):
		left += num[last][i]
	print(mid + left)


def page_sum():
	reminder = n // m
	check = []
	num = m
	ans = 0
	while True:
		diff = int(str(num)[-1])
		if diff in check:
			break
		else:
			check.append(diff)
		num += m
		ans += diff
	new_reminder = reminder // len(check)
	ans *= new_reminder
	ans += sum(check[:reminder - new_reminder * len(check)])
	return ans
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	print(page_sum())


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if b % 2 == 0:
		s = [b * 1 % 10, b * 2 % 10, b * 3 % 10, b * 4 % 10, b * 5 % 10]
		k = a // (b * len(s))
		r = a % (b * len(s))
		c = r // b
		print(k * sum(s) + sum(s[0:c]))
	else:
		s = [b * 1 % 10, b * 2 % 10, b * 3 % 10, b * 4 % 10, b * 5 % 10, b * 6 % 10, b * 7 % 10, b * 8 % 10, b * 9 % 10, 0]
		k = a // (b * len(s))
		r = a % (b * len(s))
		c = r // b
		print(k * sum(s) + sum(s[0:c]))


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


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	if str(m)[-1] == '0':
		print(0)
		continue
	if str(m)[-1] == '5':
		s = 25
	elif int(str(m)[-1]) % 2 == 0:
		s = 40
	else:
		s = 45
	ans = n // (m * 10) * s
	n -= n // (m * 10) * m * 10
	i = 1
	while n - m >= 0:
		ans += int(str(i * m)[-1])
		n -= m
		i += 1
	print(ans)


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	summ = 0
	for j in range(10):
		summ += c * j % 10
	ans = summ * (b // (c * 10))
	for j in range(1, b % (c * 10) // c + 1):
		ans += c * j % 10
	print(ans)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	arr = [0 for i in range(10)]
	for i in range(10):
		arr[i] = m * (i + 1) % 10
	sumarr = sum(arr)
	res = 0
	nproduct = n // m // 10
	res += sumarr * nproduct
	nrem = n // m % 10
	for i in range(nrem):
		res += arr[i]
	print(res)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [m * i % 10 for i in range(1, 11)]
	n = n // m
	tot = n // 10
	ans = sum(arr) * tot
	rem = n % 10
	ans += sum(arr[:rem])
	print(ans)


queries = int(input())

def books(n, m):
	l = []
	i = 1
	j = 0
	s = 0
	if n < m:
		s = 0
	if n <= 100000:
		while i <= n and j <= n:
			j = m * i
			if j > n:
				break
			else:
				l.append(m * i % 10)
			i += 1
		s = sum(l)
	else:
		for i in range(1, 1000):
			k = m * i % 10
			if k not in l:
				l.append(k)
		s = sum(l) * (n // m // len(l))
		o = n // m - len(l) * (n // m // len(l))
		for i in range(0, o):
			s += l[i]
	return s
for i in range(queries):
	nm = list(input().split(' '))
	n = int(nm[0])
	m = int(nm[1])
	print(books(n, m))


import sys
import itertools
q = None
for (c, line) in zip(itertools.count(), sys.stdin):
	if c == 0:
		q = int(line)
	elif c - 1 > q:
		break
	else:
		(n, m) = map(int, line.split(' '))
		j = n // m
		k = j % 10
		j = j // 10
		res = sum([_ * m % 10 for _ in range(10)]) * j + sum([_ * m % 10 for _ in range(k + 1)])
		print(res)


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])


for _ in range(int(input())):
	(a, b1) = input().split()
	if b1[-1] == '0' or int(b1) > int(a):
		print(0)
	else:
		b = b1[-1]
		(a, b) = (int(a), int(b))
		l = []
		for i in range(1, 10):
			s = str(i * b)
			l.append(int(s[-1]))
		pages = a // int(b1)
		su = pages // 10 * sum(l)
		k = pages % 10
		su += sum(l[:k])
		print(su)


import sys
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	if m % 10 == 0:
		print(0)
		return 0
	cycle = (0, (10, 45), (5, 20), (10, 45), (5, 20), (2, 5), (5, 20), (10, 45), (5, 20), (10, 45))
	M = m % 10
	sum = n // m // cycle[M][0] * cycle[M][1]
	n = n // m % cycle[M][0]
	for i in range(n):
		sum += M * (i + 1) % 10
	M = m
	print(sum)
t = int(input())
for _ in range(t):
	solve()


import sys

def main():
	q = int(sys.stdin.readline())
	for i in range(q):
		(n, m) = [int(x) for x in sys.stdin.readline().split(' ')]
		k = n // m
		cycles = []
		for j in range(10):
			cycles.append(m * (j + 1) % 10)
		soln = k // 10 * sum(cycles) + sum(cycles[:k % 10])
		print(soln)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	digits = []
	for i in range(1, 11):
		digits.append(k * i % 10)
	n = n // k
	ans = n // 10 * sum(digits) + sum(digits[:n % 10])
	print(ans)


for t in range(int(input())):
	x = [int(i) for i in input().split()]
	(n, m) = (x[0], x[1])
	if n == m:
		print(n % 10)
		continue
	if n < m:
		print(0)
		continue
	x = m
	dp = [0] * 10
	sumo = 0
	sumo2 = 0
	accnt = n // m
	cnt = 0
	while dp[m % 10] != 1 and m <= n:
		dp[m % 10] = 1
		sumo2 += m
		sumo += m % 10
		m = m + x
		cnt += 1
	ans = sumo * (accnt // cnt)
	m = x * (accnt // cnt) * cnt + x
	while m <= n:
		if m % x == 0:
			ans += m % 10
		m += x
	print(ans)


q = int(input())
last_digits = [0 for _ in range(9)]
for i in range(q):
	(n, k) = map(int, input().split())
	c = n // k
	for i in range(9):
		last_digits[i] = int(str((i + 1) * k)[-1])
	y = c // 10
	x = c % 10
	print(y * sum(last_digits) + sum(last_digits[:x]))


t = int(input())
for j in range(t):
	(a, b) = list(map(int, input().strip().split()))
	op = 0
	for i in range(10):
		op += i * b % 10
	x = a // b
	ans = op * (x // 10)
	for i in range(x % 10 + 1):
		ans += i * b % 10
	print(ans)


def cal(num):
	seq = []
	for i in range(1, 11):
		seq.append(int(str(num * i)[-1]))
	return seq
test = int(input())
for i in range(test):
	seq = input().split()
	page = int(seq[0])
	m = int(seq[1][-1])
	onespan = cal(m)
	turn = page // int(seq[1])
	whole = turn // 10 * sum(onespan)
	other = sum(onespan[:turn % 10])
	print(whole + other)


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	(n, m) = map(int, inp().split())
	cycle = []
	s = set()
	start = 1
	while start * m % m not in s:
		val = start * m % 10
		s.add(val)
		cycle.append(val)
		start += 1
	q = n // m
	r = q % len(cycle)
	ct = q // len(cycle) * sum(cycle) + sum(cycle[:r])
	print(ct)


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()

def div(x, y):
	s = 0
	for i in range(1, y + 1):
		s += x * i % 10
	return s
for _ in range(ii()):
	(n, m) = mi()
	x = m % 10
	p = n // m
	q = p % 10
	p //= 10
	b = div(x, 9)
	b *= p
	c = div(x, q)
	print(b + c)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	if n < m:
		print(0)
	else:
		mem = -1
		for i in range(m, n + 1, m):
			if i % 10 not in a:
				a.append(i % 10)
				mem = i
			else:
				break
		mul = n // mem
		ans = 0
		for i in range(mem * mul + m, n + 1, m):
			ans += i % 10
		ans += mul * sum(a)
		print(ans)


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


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b):
	return abs(a[0] - b[0]) + abs(b[1] - a[1])

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def eld(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()

def fac(n):
	ans = 1
	for i in range(1, n + 1):
		ans *= i
		ans %= MOD
	return ans
x = [[0 for i in range(10)] for j in range(10)]
for i in range(10):
	for j in range(1, 10):
		x[i][j] += x[i][j - 1] + int(str(i * j)[-1])
for _ in range(int(input())):
	(n, m) = arrIN()
	if n < m or m % 10 == 0:
		print(0)
	else:
		a = n // m
		t = m * a
		b = a % 10
		ans = (a - b) // 10 * x[int(str(m)[-1])][9] + x[int(str(m)[-1])][b]
		print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(n, m) = ria()
		s = 0
		i = 0
		pack = []
		for z in range(10):
			i += m
			s += i % 10
			pack.append(i % 10)
		ans = 0
		z = n // (10 * m)
		zz = z * (10 * m)
		ans += z * s
		r = (n - zz) // m
		for i in range(r):
			ans += pack[i]
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


l = []
l.append([])
l.append([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
l.append([0, 2, 4, 6, 8])
l.append([0, 3, 6, 9, 2, 5, 8, 1, 4, 7])
l.append([0, 4, 8, 2, 6])
l.append([0, 5])
l.append([0, 6, 2, 8, 4])
l.append([0, 7, 4, 1, 8, 5, 2, 9, 6, 3])
l.append([0, 8, 6, 4, 2])
l.append([0, 9, 8, 7, 6, 5, 4, 3, 2, 1])
q = int(input())
for u in range(q):
	(n, m) = [int(x) for x in input().split()]
	t = n // m
	last = int(str(m)[-1])
	if last == 0:
		print(0)
	else:
		print(sum(l[last]) * (t // len(l[last])) + sum(l[last][:t % len(l[last]) + 1]))


for _ in ' ' * int(input()):
	(n, m) = map(int, input().split())
	s = 0
	ans = 0
	if n < m:
		print(0)
	elif n == m:
		print(n % 10)
	else:
		for i in range(1, 11):
			s += i * m % 10
		res = n // m // 10 * s
		left = n // m % 10
		summ = 0
		for i in range(1, left + 1):
			summ += i * m % 10
		print(res + summ)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	b = []
	i = 1
	p = m
	while i * m % 10 != 0:
		b.append(p % 10)
		p += m
		i += 1
	b.append(0)
	c1 = n // m
	c2 = c1 // len(b)
	c3 = c1 % len(b)
	cost = 0
	for i in range(len(b) - 1):
		if i < c3:
			cost += b[i] * (c2 + 1)
		else:
			cost += b[i] * c2
	print(cost)


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	x = n // (m * 10)
	arr = [0] * 10
	s = 0
	for i in range(10):
		arr[i] = m * i % 10
		s += arr[i]
	s *= x
	n = n % (m * 10)
	i = m
	while i <= n:
		s += i % 10
		i += m
	print(s)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	l = []
	c = int(str(m)[-1])
	l.append(c)
	t = m
	for i in range(10):
		t += m
		x = int(str(t)[-1])
		if x in l:
			break
		else:
			l.append(x)
	total = n // m
	ss = sum(l)
	sss = total // len(l)
	zheng = ss * sss
	yu = total % len(l)
	for i in range(yu):
		zheng += l[i]
	print(zheng)


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


p = int(input())
l = []
for a in range(p):
	(n, m) = map(int, input().split())
	if m > n:
		l.append(0)
	else:
		ll = []
		s = 0
		for a in range(1, 11):
			ll.append(m * a % 10)
			s += m * a % 10
		x = n // m
		res = s * (x // 10)
		r = x % 10
		for b in range(r):
			res += ll[b]
		l.append(res)
for a in l:
	print(a)


from sys import stdin, stdout, setrecursionlimit
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return input()

def num():
	return int(input())

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def seive():
	prime = [1 for i in range(10 ** 6 + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(10 ** 6 + 1):
		if prime[i]:
			for j in range(2 * i, 10 ** 6 + 1, i):
				prime[j] = 0
	return prime
for _ in range(int(data())):
	(n, m) = sp()
	ans = 0
	x = n // m
	rem = x % 10
	mult = x // 10
	arr = [0] * 10
	for i in range(1, 11):
		arr[i - 1] = m * i % 10
	print(mult * sum(arr) + sum(arr[:rem]))
endtime = time.time()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(t, o) = (n // m // 10, n // m % 10)
	a = 0
	v = 0
	for i in range(1, 10):
		v += m * i % 10
		if i == o:
			a += v
	a += t * v
	print(a)


q = int(input())
for s in range(q):
	(n, m) = map(int, input().split())
	t = [int(str(m * i)[-1]) for i in range(1, 11)]
	t.append(sum(t))
	res = t[-1] * (n // (m * 10))
	for i in range(n % (m * 10) // m):
		res += t[i]
	print(res)


q = int(input())
arr = [[0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8], [0, 3, 6, 9, 2, 5, 8, 1, 4, 7], [0, 4, 8, 2, 6], [0, 5], [0, 6, 2, 8, 4], [0, 7, 4, 1, 8, 5, 2, 9, 6, 3], [0, 8, 6, 4, 2], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]]
arr1 = [[0, 1], [45, 10], [20, 5], [45, 10], [20, 5], [5, 2], [20, 5], [45, 10], [20, 5], [45, 10]]
for i in range(q):
	(n, m) = map(int, input().split(' '))
	m1 = m % 10
	a = n // m
	sum1 = 0
	sum1 += arr1[m1][0] * (a // arr1[m1][1])
	r = a % arr1[m1][1]
	for i in range(r + 1):
		sum1 += arr[m1][i]
	print(sum1)


T = int(input())
for t in range(0, T):
	L = list(map(int, input().split()))
	t = L[0]
	M = L[1]
	m = M * 10
	g = t // m
	b = 0
	s = 0
	r = t % m
	a = 0
	m = M * 10
	gx = 0
	stp = []
	for n in range(M, m, M):
		pag = str(n)
		p = len(pag)
		cifra = int(pag[p - 1])
		a = a + cifra
		bt = a * g
	for z in range(M, r + 1, M):
		pag = str(z)
		p = len(pag)
		cifra = int(pag[p - 1])
		b = b + cifra
	ris = b
	f = bt + ris
	print(f)


import sys
import math
t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	cnt = n // m
	if cnt == 0:
		print('0')
		continue
	digits = [(x + 1) * m % 10 for x in range(10)]
	digits_sum = sum(digits)
	total = digits_sum * (cnt // 10)
	rem = cnt % 10
	for i in range(rem):
		total += digits[i]
	print(total)
pass


T = int(input())
for _ in range(T):
	(n, m) = list(map(int, input().split()))
	p = [m * i % 10 for i in range(1, 11)]
	d = n // (m * 10)
	r = n % (m * 10) // m
	ans = d * sum(p)
	for i in range(r):
		ans += p[i]
	print(ans)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	if m % 10 == 0:
		ans = 0
	elif m % 5 == 0:
		d = int(n / m)
		if d % 2 == 0:
			ans = int(d * 5 / 2)
		else:
			ans = int((d + 1) * 5 / 2)
	elif m % 2 == 0:
		d = int(n / m)
		p = int(d / 5)
		k = d % 5
		ans = p * 20
		for i in range((d - k) * m, n + 1, m):
			if i % m == 0:
				ans += i % 10
	else:
		d = int(n / m)
		p = int(d / 10)
		k = d % 10
		ans = p * 45
		for i in range((d - k) * m, n + 1, m):
			if i % m == 0:
				ans += i % 10
	print(ans)
	t -= 1


num = int(input())
i = 0

def engage(x):
	i = 1
	count = 0
	while i < 11:
		v = x * i % 10
		count = count + v
		i = i + 1
	return count

def extension(req, x):
	i = 1
	sume = 0
	while i < x + 1:
		sume = sume + req * i % 10
		i = i + 1
	return sume
while i < num:
	arr = list(map(int, input().split()))
	count = 0
	count = engage(arr[1])
	r = arr[0] % arr[1]
	div = (arr[0] - r) // arr[1]
	zero = div % 10
	first = extension(arr[1], zero)
	second = div // 10
	b = second * count + first
	print(b)
	i = i + 1


T = int(input())
for _ in range(T):
	[N, M] = [int(x) for x in input().split()]
	visas = 0
	dalis = 0
	liekana = N // M % 10
	for i in range(1, 10):
		visas += i * M % 10
		if i <= liekana:
			dalis += i * M % 10
	print(visas * (N // M // 10) + dalis)


read = lambda : (int(i) for i in input().split())
count = next(read())
for _ in range(count):
	(n, m) = read()
	div = n // m
	table = [(x + 1) * (m % 10) % 10 for x in range(10)]
	sums = [sum(table[:i]) for i in range(10)]
	print(div // 10 * sums[9] + sums[div % 10])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(i, l) = (1, [])
	while i * m % 10 not in l:
		l.append(i * m % 10)
		i += 1
	extra = 0
	print(n // (m * (i - 1)) * sum(l) + sum(l[:n % (m * (i - 1)) // m]))


def read():
	(n, m) = map(int, input().split())
	return (n, m)

def solve(n, m):
	last = m % 10
	p = [0] * 11
	for i in range(1, 11):
		p[i] = last * i % 10
	dig_count = n // m
	(full_rounds, rest) = divmod(dig_count, 10)
	return full_rounds * sum(p[1:11]) + sum(p[1:rest + 1])
for t in range(int(input())):
	result = solve(*read())
	print(result)


for rpt in range(int(input())):
	(n, m) = [int(x) for x in input().split(' ')]
	digits = [m % 10]
	for i in range(2, 11):
		last_digit = m * i % 10
		if last_digit in digits:
			break
		else:
			digits.append(last_digit)
	n = n // m
	all_digits = n // len(digits)
	rest = n % len(digits)
	res = all_digits * sum(digits)
	for i in range(rest):
		res += digits[i]
	print(res)


mat = [[], [10, 45, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [5, 20, 2, 4, 6, 8, 0], [10, 45, 3, 6, 9, 2, 5, 8, 1, 4, 7, 0], [5, 20, 4, 8, 2, 6, 0], [2, 5, 5, 0], [5, 20, 6, 2, 8, 4, 0], [10, 45, 7, 4, 1, 8, 5, 2, 9, 6, 3, 0], [5, 20, 8, 6, 4, 2, 0], [10, 45, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	soma = 0
	j = m % 10
	if j > 0:
		soma = n // (mat[j][0] * m) * mat[j][1]
		k = n % (mat[j][0] * m) // m
		for i in range(k):
			soma += mat[j][i + 2]
	print(soma)


t = int(input())
Ans = ''
for p in range(t):
	(n, m) = map(int, input().split())
	nums = n // m
	d = [m % 10]
	ans = 0
	i = 2
	s = m % 10
	while d[0] != m * i % 10:
		d.append(m * i % 10)
		s += m * i % 10
		i += 1
	l = len(d)
	ans += nums // l * s
	for i in range(nums % l):
		ans += d[i]
	Ans += str(ans) + '\n'
	ans = 0
print(Ans)


count = int(input())
for i in range(count):
	a = []
	suma = 0
	ars = 0
	(o, o1) = map(int, input().split())
	su = o // o1
	for i in range(1, 11):
		suma += int(str(i * o1)[-1])
		a.append(int(str(i * o1)[-1]))
	for i in range(su % 10):
		ars += a[i]
	print(su // 10 * suma + ars)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	q = n // m
	r = m % 10
	aze = []
	i = 1
	while i * r % 10 != 0 and i <= q:
		aze.append(i * r % 10)
		i += 1
	ans += sum(aze) * (q // i) + sum(aze[:q % i])
	print(ans)


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


for _ in range(int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	num = n // m
	s = 0
	for i in range(1, 11):
		s += m * i % 10
	s = num // 10 * s
	for i in range(1, num % 10 + 1):
		s += m * i % 10
	print(s)


t = int(input())
d = [[]] * 10
d[1] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
d[2] = [2, 4, 6, 8, 0]
d[3] = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
d[4] = [4, 8, 2, 6, 0]
d[5] = [5, 0]
d[6] = [6, 2, 8, 4, 0]
d[7] = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
d[8] = [8, 6, 4, 2, 0]
d[9] = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
dd = [10, 5, 10, 5, 2, 5, 10, 5, 10]
for i in range(t):
	(n, m) = map(int, input().split())
	if m <= n:
		a = n // m
		b = m % 10
		c = a // dd[b - 1]
		cc = a % dd[b - 1]
		print(c * sum(d[b]) + sum(d[b][:cc]))
	else:
		print(0)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if m > n:
		print(0)
	elif m == n:
		print(str(n)[-1])
	else:
		mm = m
		arr = []
		last = str(mm)[-1]
		while last not in arr:
			arr.append(last)
			mm += m
			last = str(mm)[-1]
		arr = [int(i) for i in arr]
		number_of_elements = len(arr)
		tot_numbers = n // m
		ans = sum(arr) * (tot_numbers // number_of_elements)
		left = tot_numbers % number_of_elements
		ans += sum(arr[:left])
		print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if m == 0:
		print(0)
		continue
	k = m
	count = 1
	s = m % 10
	while k % 10 != 0:
		k += m
		k = k % 10
		s += k
		count += 1
	answer = n // m // count * s
	n = n // m % count
	k = 0
	for i in range(n):
		k += m
		k = k % 10
		answer = answer + k
	print(answer)


n_ = int(input())
for i in range(n_):
	sum_ = []
	(m, n) = list(map(int, input().split()))
	last_digit_10 = [n * i % 10 for i in range(1, 11)]
	times = m // (n * 10)
	last_digit_10 = sum(last_digit_10) * times
	rem_sum = 0
	for i in range(n * 10 * times + n, m + 1, n):
		if i % n == 0:
			rem_sum += i % 10
	print(rem_sum + last_digit_10)


n = int(input())
for i in range(n):
	s = input().split()
	pages = int(s[0])
	div = int(s[1])
	last = div % 10
	cur = [0] * 10
	if last != 0:
		cur = list(range(0, last * 10 + 1, last))[1:]
		cur = [i % 10 for i in cur]
	mult = pages // (div * 10)
	rem = pages % (div * 10) // div
	print(mult * sum(cur) + sum(cur[:rem]))


def get_last_digits(m):
	i = 1
	digits = []
	while int(str(m * i)[-1]) != 0:
		digits.append(int(str(m * i)[-1]))
		i += 1
	digits.append(int(str(m * i)[-1]))
	return digits

def sum_last_digits(n, m, digits):
	s = 0
	s = n // m // len(digits) * sum(digits)
	mod = n // m % len(digits)
	s += sum(digits[:mod])
	return s
q = int(input())
queries = []
result = []
for i in range(q):
	(n, m) = input().split(' ')
	queries.append([int(n), int(m)])
for i in range(q):
	digits = get_last_digits(queries[i][1])
	print(sum_last_digits(queries[i][0], queries[i][1], digits))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		print(0)
	else:
		v = [str(b)[-1]]
		for i in range(2, 11):
			z = str(b * i)
			if z[-1] == v[0]:
				break
			else:
				v.append(z[-1])
		w = sum(map(int, v))
		q = a // b
		r = q // len(v) * w
		for j in range(q % len(v)):
			r += int(v[j])
		print(r)


dc = [[j * i % 10 for j in range(10)] for i in range(10)]
for t in range(int(input())):
	(n, m) = map(int, input().split())
	(d, k) = (m % 10, n // m)
	print(k // 10 * sum(dc[d]) + sum(dc[d][:k % 10 + 1]))


def last_digit(num):
	return num % 10
q = int(input())
for i in range(q):
	s = 0
	(n, m) = map(int, input().split())
	j = m
	while j < m * 10 and j <= n:
		s += last_digit(j)
		j += m
	if m * 10 < n:
		nn = n // (m * 10)
		s = s * nn
		j = n % (m * 10)
		k = m
		while k <= j:
			s += last_digit(k)
			k += m
		print(s)
	else:
		print(s)


p = int(input())
while p:
	(n, m) = map(int, input().split())
	k = n // m
	l = []
	for i in range(10):
		l.append((i + 1) * m % 10)
	sum1 = 0
	for i in range(k % 10):
		sum1 += l[i]
	print(k // 10 * sum(l) + sum1)
	p -= 1


n = int(input())
for x in range(n):
	(n, m) = map(int, input().split())
	a = n // m
	b = a // 10
	e = 0
	o = 0
	for i in range(1, 11):
		c = str(m * i)[::-1][0]
		e += int(c)
	for i in range(b * 10 + 1, a + 1):
		q = str(i * m)[::-1][0]
		o += int(q)
	print(b * e + o)


t = int(input())
while t > 0:
	s = list(map(int, input().split(' ')))
	n = s[0]
	m = s[1]
	st = []
	for i in range(1, 11):
		num = i * m
		last_dig = num % 10
		if last_dig not in st:
			st.append(last_dig)
	set_sum = sum(st)
	length = len(st)
	total_number = n // m
	ans = total_number // length
	ans = ans * set_sum
	left = total_number % length
	for i in range(left):
		ans += st[i]
	print(ans)
	t = t - 1


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	a = []
	for i in range(1, 11):
		a.append(m * i % 10)
	cnt = 0
	n = n // m
	if n <= 10:
		for i in range(n):
			cnt += a[i]
		print(cnt)
	else:
		cnt += sum(a) * (n // 10)
		n = n % 10
		for i in range(n):
			cnt += a[i]
		print(cnt)


q = int(input())
for j in range(q):
	(n, m) = list(map(int, input().split()))
	goo = []
	for i in range(1, 11):
		k = str(m * i)
		goo.append(int(k[-1]))
	s = sum(goo)
	t = n // m
	count = t // 10
	ans = count * s
	ans += sum(goo[:t % 10])
	print(ans)


print(*[[[[m * x % 10 if a.append(m * x % 10) is None else m * x % 10 for x in range(1, 11) if m * x % 10 not in a and len(set(a)) == len(a)], sum(a) * (n // m // len(a)) + sum(a[:n // m % len(a)])][1] for (n, m, a) in [[*map(int, input().split()), []]]][0] for q in range(int(input()))], sep='\n')


def answer():
	(n, m) = map(int, input().split(' '))
	m2 = m % 10
	cumsums = [0]
	last_digits = [0]
	last_digit = 0
	cumsum = 0
	for i in range(10):
		last_digit = (last_digit + m2) % 10
		last_digits.append(last_digit)
		cumsum = cumsum + last_digit
		cumsums.append(cumsum)
	sum_last_digit = sum(last_digits)
	r1 = n // m
	r2 = r1 // 10
	r3 = r1 % 10
	q = n % m
	out = r2 * sum_last_digit + cumsums[r3]
	return out
nn = int(input())
for _ in range(nn):
	out = answer()
	print(out)


def summa(n, m):
	if n < m:
		return 0
	elif n == m:
		return n % 10
	else:
		s = 0
		res = n // m
		b = []
		i = 0
		while True:
			b.append(m * (i + 1) % 10)
			if len(b) > 2:
				if b[-1] == b[1] and b[-2] == b[0]:
					b.pop()
					b.pop()
					break
			i += 1
		pred_s = sum(b)
		length = len(b)
		p = res // length
		s += p * pred_s
		l = res % length
		for k in range(l):
			s += b[k]
		return s
q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	print(summa(a, b))


qs = int(input())
tabl = []
for i in range(10):
	tabl.append([])
	for j in range(10):
		tabl[i].append(i * j % 10)
for q in range(qs):
	ans = 0
	(n, m) = [int(elem) for elem in input().split()]
	k = n // m
	z = k // 10
	y = k % 10
	full = 0
	for i in range(10):
		full += tabl[m % 10][i]
	full = full * z
	not_full = 0
	for i in range(y):
		not_full += tabl[m % 10][i + 1]
	ans = full + not_full
	print(ans)


q = int(input())
for i in range(q):
	x = input()
	x = x.split()
	n = int(x[0])
	m = int(x[1])
	counter = 0
	mm = m
	num = n // m
	devisions = [m * i % 10 for i in range(1, 11)]
	s = sum(devisions)
	left = num % 10
	counter = num // 10 * s
	for j in range(left):
		counter += devisions[j]
	print(counter)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	(m, n) = (n, m)
	m = m // n
	a = [0] * 10
	ans = 0
	for j in range(11, 21):
		a[j % 10] = n * j % 10
	k = m // 10
	z = m % 10
	for j in range(10):
		if j == 0:
			ans += max(0, (k - 1) * a[j])
		else:
			ans += k * a[j]
	for j in range(1, z + 1):
		ans += a[j]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print(0)
		continue
	elif m % 10 == 0:
		print(0)
	else:
		d = m % 10
		f = n // m
		a = 0
		if d % 2 == 0:
			k = f // 5
			k1 = f % 5
			a += k * 20
			for i in range(1, k1 + 1):
				a += d * i % 10
			print(a)
		elif d % 2 == 1 and d != 5:
			k = f // 10
			k1 = f % 10
			a += k * 45
			for i in range(1, k1 + 1):
				a += d * i % 10
			print(a)
		else:
			k = f // 2
			k1 = f % 2
			a += k * 5
			for i in range(1, k1 + 1):
				a += d * i % 10
			print(a)


def LCM(x, y):
	(x, y) = (max(x, y), min(x, y))
	lcm = x * y
	for i in range(1, y):
		if i * x % y == 0:
			lcm = x * i
			break
	return lcm
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	x = LCM(m, 10) // m
	seq_s = 0
	for i in range(1, x + 1):
		seq_s += m * i % 10
	gota = n // m // x
	extra = n // m % x
	extra_wt = 0
	for i in range(1, extra + 1):
		extra_wt += m * i % 10
	print(gota * seq_s + extra_wt)


t = int(input())
for i in range(0, t):
	(m, n) = map(int, input().split())
	a = m // n
	r = n % 10
	lis = [r]
	i = -1
	k = 2
	while i != r:
		i = r * k % 10
		k = k + 1
		if i == r:
			break
		lis.append(i)
	temp = a // len(lis)
	ji = temp * sum(lis)
	temp2 = a % len(lis)
	for i in lis:
		if i == lis[temp2]:
			break
		ji = ji + i
	print(ji)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	c = 0
	d = {0: 0, 1: 45, 9: 45, 2: 40, 8: 40, 3: 45, 7: 45, 4: 40, 6: 40, 5: 25}
	a = n // m
	l_m = m % 10
	c = d[l_m] * (a // 10)
	b = a % 10
	i = 1
	j = l_m
	while i <= b:
		c += j % 10
		i += 1
		j = l_m * i
	print(c)
	t -= 1


query = int(input())
for i in range(query):
	x = input()
	x = x.split(' ')
	n = int(x[0])
	m = int(x[1])
	if n >= 10 * m:
		x = 10 * m
		digits = 0
		result = 0
		newm = m
		while newm < x:
			digits += newm % 10
			newm += m
		result += digits * (n // m // 10)
		x = n - n // m // 10 * 10 * m
		digits = 0
		newm = m
		while newm <= x:
			digits += newm % 10
			newm += m
		result += digits
		print(result)
	elif n < m:
		print(0)
	elif n == m:
		print(m % 10)
	else:
		result = 0
		x = m * (n // m)
		newm = m
		while newm <= x:
			result += newm % 10
			newm += m
		print(result)


from collections import deque as d
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	cur = m % 10
	l = d([cur])
	num = n // m
	while True:
		cur = (cur + m) % 10
		if cur in l:
			break
		else:
			l.append(cur)
	le = len(l)
	t = num // le
	rest = num % le
	l = list(l)
	print(t * sum(l) + sum(l[:rest]))


t = int(input())
for _ in range(t):
	(n, m) = [int(t) for t in input().split(' ')]
	digits = []
	mi = m
	while True:
		mm = mi % 10
		if mm in digits:
			break
		digits.append(mm)
		mi += m
	nm = n // m
	print(nm // len(digits) * sum(digits) + sum(digits[:nm % len(digits)]))


prm = {1: 10, 2: 5, 3: 10, 4: 5, 5: 2, 6: 5, 7: 10, 8: 5, 9: 10}
for case in range(int(input())):
	(N, K) = input().split()
	N = int(N)
	K = int(K)
	a = N // K
	k = K % 10
	if k > 0:
		b = a // prm[k]
		c = a % prm[k]
		if prm[k] == 5:
			ans = b * 20
		elif prm[k] == 10:
			ans = b * 45
		elif prm[k] == 2:
			ans = b * 5
		for i in range(1, c + 1):
			ans += i * k % 10
	else:
		ans = 0
	print(ans)


def tensm(x):
	sm = sum([x * y % 10 for y in range(1, 11)])
	gp = x * 10
	return (sm, gp)
for _ in range(int(input())):
	(n, m) = (*map(int, input().split()),)
	(tsm, tgp) = tensm(m)
	sm = tsm * (n // tgp)
	st = tgp * (n // tgp) + m
	while st <= n:
		sm += st % 10
		st += m
	print(sm)


q = int(input())
while q:
	(n, m) = map(int, input().split())
	s = n // m
	res = 0
	if s:
		s1 = 0
		for i in range(1, 10):
			s1 += m * i % 10
		s2 = s % 10
		for i in range(1, s2 + 1):
			res += m * i % 10
		res += s // 10 * s1
	print(res)
	q -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		print(0)
		continue
	else:
		d = m % 10
		f = n // m
		k = f // 10
		c10 = 0
		for i in range(1, 11):
			c10 += d * i % 10
		a = k * c10
		for i in range(f % 10):
			a += d * (i + 1) % 10
		print(a)


from math import *
from sys import *
from collections import defaultdict
M = 10 ** 9 + 7

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def factor(n):
	potentional_p = 3
	itog_list = {}
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			if n in itog_list:
				itog_list[n] += 1
			else:
				itog_list[n] = 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			if potentional_p in itog_list:
				itog_list[potentional_p] += 1
			else:
				itog_list[potentional_p] = 1
		potentional_p += 2
	return itog_list

def meth(m):
	if m == 1:
		return [i for i in range(1, 10)] + [0]
	if m == 2:
		return [2, 4, 6, 8, 0]
	if m == 3:
		return [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
	if m == 4:
		return [4, 8, 2, 6, 0]
	if m == 5:
		return [5, 0]
	if m == 6:
		return [6, 2, 8, 4, 0]
	if m == 7:
		return [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
	if m == 8:
		return [8, 6, 4, 2, 0]
	if m == 9:
		return [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
	if m == 0:
		return [0]
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, stdin.readline().split()))
	dif = meth(int(str(m)[-1]))
	val = int(n // m)
	ln = len(dif)
	res = val // ln * sum(dif)
	val -= val // ln * ln
	res += sum(dif[:val])
	print(res)


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


n = int(input())
li = []
for i in range(n):
	(a, b) = map(int, input().split())
	c = a // b
	d = c // 10
	e = c % 10
	b = b % 10
	for i in range(1, 10):
		li.append(b * i % 10)
	result = sum(li) * d + sum(li[:e])
	print(result)
	li.clear()


try:
	test = int(input())
	while test:
		test -= 1
		(n, m) = map(int, input().split())
		if m == n:
			m = str(m)
			print(m[len(m) - 1])
		elif m > n:
			print(0)
		elif m == 1:
			t = n // 10
			re = n - 10 * t
			print(re * (re + 1) // 2 + 45 * t)
		else:
			ns = 0
			for i in range(1, 10):
				nu = m * i
				nu = str(nu)
				ns += int(nu[len(nu) - 1])
			di = n // m
			t = di // 10
			re = di - 10 * t
			curr = 0
			for i in range(1, re + 1):
				nu = m * i
				nu = str(nu)
				curr += int(nu[len(nu) - 1])
			print(curr + ns * t)
except:
	pass


dic = {0: 0, 1: 45, 2: 40, 3: 45, 4: 40, 5: 25, 6: 40, 7: 45, 8: 40, 9: 45}
le = int(input())
for _ in range(le):
	ans = 0
	(n, m) = map(int, input().split())
	div = n // m
	ans += div // 10 * dic[m % 10]
	for j in range(1, div % 10 + 1):
		ans += m % 10 * j % 10
	print(ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	l = []
	cur = m
	while True:
		if int(str(cur)[-1]) in l:
			(a, b) = divmod(n // m, len(l))
			print(a * sum(l) + sum(l[:b]))
			break
		else:
			l.append(int(str(cur)[-1]))
			cur += m


import os
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	sum = 0
	d = n // m
	for i in range(1, 10):
		sum += m * i % 10
	i = d % 10
	d = d - i
	sum = sum * d // 10
	for j in range(1, i + 1):
		sum += m * j % 10
	print(sum)


Q = int(input())
from itertools import accumulate
ans = []
for q in range(Q):
	(n, m) = map(int, input().split())
	target = []
	z = m
	for i in range(10):
		target.append(z % 10)
		z += m
	tar_acc = list(accumulate(target))
	tmp = n // (10 * m)
	X = sum(target) * tmp
	if (n - m * 10 * tmp) // m >= 1:
		X += tar_acc[(n - m * 10 * tmp) // m - 1]
	ans.append(X)
for a in ans:
	print(a)


t = int(input())
for j in range(t):
	(n, m) = [int(x) for x in input().split()]
	s = 0
	a = []
	for i in range(m, n + 1, m):
		x = i % 10
		if x in a:
			break
		s += x
		a.append(x)
	k = n // m
	if k > len(a):
		s *= k // len(a)
		x = k % len(a)
		if x:
			for i in range(x):
				s += a[i]
	print(s)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	k = m % 10
	ans = 0
	if k == 1 or k == 3 or k == 7 or (k == 9):
		ans = n // m // 10 * 45
		t = n // m % 10
		q = k
		for _ in range(t):
			ans += q % 10
			q += k
	elif k == 2 or k == 4 or k == 6 or (k == 8):
		ans = n // m // 5 * 20
		t = n // m % 5
		q = k
		for _ in range(t):
			ans += q % 10
			q += k
	elif k == 5:
		ans = (n // m + 1) // 2 * 5
	elif k == 0:
		ans = 0
	print(ans)


digit_loops = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 45], [2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 40], [3, 6, 9, 2, 5, 8, 1, 4, 7, 0, 45], [4, 8, 2, 6, 0, 4, 8, 2, 6, 0, 40], [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 25], [6, 2, 8, 4, 0, 6, 2, 8, 4, 0, 40], [7, 4, 1, 8, 5, 2, 9, 6, 3, 0, 45], [8, 6, 4, 2, 0, 8, 6, 4, 2, 0, 40], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 45]]
t = int(input())
for q in range(t):
	(n, m) = map(int, input().split())
	d = m % 10
	n = n // m
	loop = digit_loops[d]
	r = loop[10] * (n // 10) + sum(loop[:n % 10])
	print(r)


def number(n, m):
	(s, k) = (0, [])
	for i in range(1, 10 + 1):
		k.append(i * m % 10)
		s += i * m % 10
	p = n // m
	l = p % 10
	return s * (p - l) // 10 + sum(k[:l])
for i in range(int(input())):
	(n, m) = list(map(int, input().strip().split()))
	print(number(n, m))


for q in range(int(input())):
	(n, m) = list(map(int, input().split()))
	sum1 = 0
	for i in range(1, 11):
		sum1 += m * i % 10
	t = n // m
	t1 = t // 10
	t2 = t % 10
	sum1 *= t1
	for i in range(1, t2 + 1):
		sum1 += m * i % 10
	print(sum1)


q = int(input())
while q > 0:
	(n, m) = list(map(int, input().rstrip().split(' ')))
	k = n // m
	su = 0
	for i in range(1, 11):
		su = su + m * i % 10
	su = k // 10 * su
	for i in range(1, k % 10 + 1):
		su += m * i % 10
	print(su)
	q = q - 1


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

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

def sep_input():
	return map(int, input().split())
for _ in range(int(input())):
	(n, m) = sep_input()
	c = n // m
	if c == 0:
		print(0)
	else:
		a = c // 10
		b = c % 10
		l = [m * i % 10 for i in range(1, 11)]
		s = sum(l)
		ans = s * a + sum(l[:b])
		print(ans)


def findLast(m):
	digits = []
	for i in range(1, 11):
		if m * i % 10 == 0:
			digits.append(0)
			break
		digits.append(m * i % 10)
	return digits
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	digits = findLast(m)
	numOfDivisors = n // m
	repetitions = numOfDivisors // len(digits)
	leftover = numOfDivisors % len(digits)
	result = sum(digits) * repetitions + sum(digits[:leftover])
	print(result)


lista0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
lista1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
lista2 = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0]
lista3 = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]
lista4 = [4, 8, 2, 6, 0, 4, 8, 2, 6, 0]
lista5 = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0]
lista6 = [6, 2, 8, 4, 0, 6, 2, 8, 4, 0]
lista7 = [7, 4, 1, 8, 5, 2, 9, 6, 3, 0]
lista8 = [8, 6, 4, 2, 0, 8, 6, 4, 2, 0]
lista9 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
lista = [lista0, lista1, lista2, lista3, lista4, lista5, lista6, lista7, lista8, lista9]
casos = int(input())
for i in range(casos):
	(n, m) = [int(x) for x in input().split()]
	possibilidades = n // m
	sum = 0
	ultimoDigito = m % 10
	for i in range(len(lista[ultimoDigito])):
		sum += lista[ultimoDigito][i]
	sum *= possibilidades // 10
	for i in range(0, possibilidades % 10):
		sum += lista[ultimoDigito][i % 10]
	print(sum)


q = int(input())
for j in range(q):
	(n, m) = map(int, input().split())
	if m > n:
		print(0)
		continue
	first_ten_numbers_sum = 0
	numbers = []
	digit = 0
	s = 0
	for i in range(10):
		digit += m
		numbers.append(int(str(digit)[::-1][0]))
	for i in range(10):
		s += numbers[i]
	final_sum = n // (m * 10) * s
	for i in range(n % (m * 10) // m):
		final_sum += numbers[i]
	print(final_sum)


t = int(input())
for i in range(t):
	a = [int(x) for x in input().split()]
	n = a[0]
	m = a[1]
	digit = []
	d = m % 10
	while not digit or digit[0] != d:
		digit.append(d)
		d = (d + m % 10) % 10
	cnt = n // m
	res = sum(digit) * (cnt // len(digit))
	if cnt % len(digit):
		res += sum(digit[:cnt % len(digit)])
	print(res)


import sys

def main():
	q = int(sys.stdin.readline().strip())
	for _ in range(q):
		(n, m) = [int(s) for s in sys.stdin.readline().strip().split()]
		n //= m
		ds = set()
		x = m
		while x % 10 not in ds:
			ds.add(x % 10)
			x += m
		res = sum(ds) * (n // len(ds))
		n %= len(ds)
		x = m
		while n > 0:
			res += x % 10
			x += m
			n -= 1
		print(res)
main()


q = int(input())
for i in range(q):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	s = 0
	if m % 2 == 0:
		for i in range(m, m * 5 + 1, m):
			s += i % 10
		s *= n // (m * 5)
		for i in range(n // (m * 5) * (m * 5) + m, n + 1, m):
			s += i % 10
	else:
		for i in range(m, m * 10 + 1, m):
			s += i % 10
		s *= n // (m * 10)
		for i in range(n // (m * 10) * (m * 10) + m, n + 1, m):
			s += i % 10
	print(s)


def get_till_10(m):
	out = [m * i % 10 for i in range(1, 11)]
	return (sum(out), out)

def handle_case(n, m):
	if n < m:
		print(0)
		return
	k = n // (m * 10)
	(sum_till_10, arr_till_10) = get_till_10(m)
	remain = (n - k * m * 10) // m
	out = sum_till_10 * k + sum(arr_till_10[:remain])
	print(out)

def run():
	num_queries = eval(input())
	queries = []
	for _ in range(num_queries):
		queries.append(list(map(int, input().split())))
	for query in queries:
		(n, m) = query
		handle_case(n, m)
run()


t = int(input())
for test in range(t):
	(n, m) = map(int, input().split(' '))
	count = n // m
	check = m % 10
	res = 0
	if check % 2 == 0:
		if check == 0:
			res = 0
		else:
			res += 20 * (count // 5)
			count = count - 5 * (count // 5)
			check1 = check
			while count > 0:
				res += check1
				check1 = (check1 + check) % 10
				count -= 1
	elif check == 1 or check == 3 or check == 7 or (check == 9):
		res += 45 * (count // 10)
		count -= 10 * (count // 10)
		check1 = check
		while count > 0:
			res += check1
			check1 = (check1 + check) % 10
			count -= 1
	elif check == 5:
		res += 5 * (count // 2)
		count -= 2 * (count // 2)
		check1 = check
		while count > 0:
			res += check1
			check1 = (check1 + check) % 10
			count -= 1
	print(res)


q = int(input())
for query in range(q):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	s = 0
	for i in range(10):
		s += int(str(m * i)[-1])
	k = n // (10 * m) * s
	l = n % (10 * m)
	c = m
	while c <= l:
		k += int(str(c)[-1])
		c += m
	print(k)


def problem():
	T = int(input())
	while T:
		(n, m) = [int(x) for x in input().split(' ')]
		k = n // m
		k = k * m
		lines = int(k / (10 * m))
		offset = int(k % (10 * m))
		offset_count = offset // m
		l = list()
		i = 1
		while i <= 10:
			num = i * m
			l.append(num % 10)
			i += 1
		_sum = 0
		i = 0
		while i < 10:
			_sum += l[i] * lines
			i += 1
		i = 0
		while i < offset_count:
			_sum += l[i]
			i += 1
		print(_sum)
		T -= 1
problem()


t = int(input())
for _ in range(t):
	nu = []
	(n, m) = list(map(int, input().split()))
	for j in range(1, 11):
		nu.append(m * j % 10)
	val = n % (m * 10)
	quo = (n - val) // (m * 10)
	ans = 1
	ans = quo * sum(nu)
	i = 0
	while val > 0:
		val -= m
		if val < 0:
			break
		ans += nu[i]
		i += 1
	print(ans)


q = int(input())
while q > 0:
	q -= 1
	(n, m) = map(int, input().split())
	a = []
	a.append(0)
	for i in range(1, 11):
		a.append(a[i - 1] + m * i % 10)
	x = n // m
	y = x // 10
	z = x % 10
	c = y * a[10] + a[z]
	print(c)