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

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

You have to answer q independent queries.

Input

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

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

Output

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

Example

Input


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


Output


1
45
153
294
3359835
0
427262129093995
#include <bits/stdc++.h>
using namespace std;
void base() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
bool prime[100001];
void sieve(long long int n) {
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long double float_sq(long double n) {
  long double x = n;
  long double y = 1;
  long double e = 0.000001;
  while (x - y > e) {
    x = (x + y) / 2;
    y = n / x;
  }
  return x;
}
long long int int_sq(long long int x) {
  if (x == 0 || x == 1) return x;
  long long int start = 1, end = x, ans;
  while (start <= end) {
    long long int mid = (start + end) / 2;
    if (mid * mid == x) return mid;
    if (mid * mid < x) {
      start = mid + 1;
      ans = mid;
    } else
      end = mid - 1;
  }
  return ans;
}
long long int nxt() {
  long long int x;
  cin >> x;
  return x;
}
bool ispalindrome(string str) {
  vector<char> List;
  for (long long int i = 0; i < str.length(); i++) {
    auto pos = find(List.begin(), List.end(), str[i]);
    if (pos != List.end()) {
      auto posi = find(List.begin(), List.end(), str[i]);
      List.erase(posi);
    } else
      List.push_back(str[i]);
  }
  if (str.length() % 2 == 0 && List.empty() ||
      (str.length() % 2 == 1 && List.size() == 1))
    return true;
  else
    return false;
}
long long int cnt = 0;
void printArray(vector<long long int> arr, long long int n) {
  long long int a = arr[0], b = arr[0], c = arr[0];
  for (long long int i = 1; i < arr.size(); i++) {
    a ^= arr[i];
    b |= arr[i];
    c &= arr[i];
  }
  if (a == b && b == c) cnt++;
}
void printSubsequences(vector<long long int> arr, long long int index,
                       vector<long long int> subarr) {
  if (index == arr.size()) {
    long long int l = subarr.size();
    if (l != 0) printArray(subarr, l);
  } else {
    printSubsequences(arr, index + 1, subarr);
    subarr.push_back(arr[index]);
    printSubsequences(arr, index + 1, subarr);
  }
  return;
}
bool palindrome(string s) {
  string test = s;
  reverse(test.begin(), test.end());
  return s == test;
}
long long int fast_power(long long int x, long long int y, long long int m) {
  if (y == 0) return 1;
  long long int temp = fast_power(x, y / 2, m);
  temp = (temp * temp) % m;
  if (y % 2 != 0) temp = (temp * x) % m;
  return temp;
}
long long int inv(long long int x, long long int m) {
  return fast_power(x, m - 2, m);
}
bool comp(const pair<pair<long long int, long long int>,
                     pair<long long int, long long int>>& a,
          const pair<pair<long long int, long long int>,
                     pair<long long int, long long int>>& b) {
  if (a.second.first == b.second.first) return a.first.first < b.first.first;
  return a.second.first > b.second.first;
}
int32_t main() {
  base();
  long long int q = nxt();
  map<long long int, bool> m;
  vector<long long int> v;
  while (q--) {
    long long int n = nxt(), b = nxt();
    long long int cnt = 0;
    if (n < b) {
      cout << 0 << "\n";
      continue;
    }
    for (long long int i = b; i <= n; i += b) {
      if (!m[i % 10]) {
        v.push_back(i % 10);
        cnt += i % 10;
      } else
        break;
      m[i % 10] = 1;
    }
    long long int ans = (n / b) / v.size();
    ans *= cnt;
    for (long long int i = 0; i < (n / b) % v.size(); i++) ans += v[i];
    cout << ans << "\n";
    m.clear();
    v.clear();
  }
  return 0;
}
