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;
long long bin_search(vector<pair<long long, long long> > &v, long long x,
                     long long n) {
  long long f = 0, l = v.size() - 1;
  while (f <= l) {
    long long m = (f + l) / 2;
    if (v[m].first == x)
      return m;
    else {
      if (v[m].first > x) {
        l = m - 1;
      } else {
        f = m + 1;
      }
    }
  }
  return -1;
}
long long dfs(vector<long long> &v, vector<long long> &x,
              vector<long long> &vis, long long u, long long par, long long s) {
  if (vis[u]) {
    return s;
  }
  vis[u] = 1;
  s++;
  return x[u] = dfs(v, x, vis, v[u] - 1, u, s);
}
bool isPrime(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
bool isPalin(long long x) {
  string s = to_string(x);
  long long i = 0, j = s.size() - 1;
  while (i <= j) {
    if (s[i] != s[j]) return false;
    i++;
    j--;
  }
  return true;
}
long long find(vector<long long> &p, long long x) {
  if (p[x] == x)
    return x;
  else
    return find(p, p[x]);
}
void build(vector<long long> &p, long long par, long long u) {
  p[u] = par;
  return;
}
void toh(vector<pair<long long, long long> > &v, long long n, long long i,
         long long f) {
  if (n == 1) {
    v.push_back(make_pair(i, f));
    return;
  }
  toh(v, n - 1, i, 6 - i - f);
  v.push_back(make_pair(i, f));
  toh(v, n - 1, 6 - i - f, f);
}
void builds(vector<long long> &v, vector<long long> &s, long long u,
            long long l, long long r) {
  if (l == r) {
    s[u] = v[u];
  } else {
    long long m = (l + r) / 2;
    builds(v, s, u * 2, l, m);
    builds(v, s, u * 2 + 1, m + 1, r);
    s[u] = min(s[u * 2], s[u * 2 + 1]);
  }
}
long long req(vector<long long> &s, long long u, long long l, long long r,
              long long tl, long long tr) {
  if (l > r) return 0;
  if (l == tl && r == tr) return s[u];
  long long tm = (tl + tr) / 2;
  return min(req(s, u * 2, l, min(r, tm), tl, tm),
             req(s, u * 2, max(l, tm + 1), r, tm + 1, tr));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long w = 1;
  cin >> w;
  while (w--) {
    long long n, m;
    cin >> n >> m;
    long long x = 0;
    n /= m;
    long long y1 = n / 10, y2 = n % 10;
    for (long long i = 1; i < 11; i++) {
      x += ((m * i) % 10);
    }
    long long c = 0;
    for (long long i = 1; i < y2 + 1; i++) {
      c += ((m * i) % 10);
    }
    cout << x * y1 + c << endl;
  }
  return 0;
}
