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;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    long long int r1 = 45;
    long long int s1 = 10;
    long long int r2 = 20;
    long long int s2 = 5;
    long long int r3 = 45;
    long long int s3 = 10;
    long long int r4 = 20;
    long long int s4 = 5;
    long long int r5 = 5;
    long long int s5 = 2;
    long long int r6 = 20;
    long long int s6 = 5;
    long long int r7 = 45;
    long long int s7 = 10;
    long long int r8 = 20;
    long long int s8 = 5;
    long long int r9 = 45;
    long long int s9 = 10;
    long long int digit = b % 10;
    long long int sum = 0;
    if (digit == 1) {
      sum = (a / (b * s1)) * r1;
      long long int loop = ((b * s1) * (a / (b * s1))) + b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    if (digit == 2) {
      sum = (a / (b * s2)) * r2;
      long long int loop = ((b * s2) * (a / (b * s2))) + b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    if (digit == 3) {
      sum = (a / (b * s3)) * r3;
      long long int loop = ((b * s3) * (a / (b * s3))) + b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    if (digit == 4) {
      sum = (a / (b * s4));
      sum *= r4;
      long long int loop = (a / (b * s4));
      loop *= (b * s4);
      loop += b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    if (digit == 5) {
      sum = (a / (b * s5)) * r5;
      long long int loop = ((b * s5) * (a / (b * s5))) + b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    if (digit == 6) {
      sum = (a / (b * s6)) * r6;
      long long int loop = ((b * s6) * (a / (b * s6))) + b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    if (digit == 7) {
      sum = (a / (b * s7)) * r7;
      long long int loop = ((b * s7) * (a / (b * s7))) + b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    if (digit == 8) {
      sum = (a / (b * s8)) * r8;
      long long int loop = ((b * s8) * (a / (b * s8))) + b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    if (digit == 9) {
      sum = (a / (b * s9)) * r9;
      long long int loop = ((b * s9) * (a / (b * s9))) + b;
      for (long long int i = loop; i <= a; i = i + b) {
        sum += i % 10;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
