#include <bits/stdc++.h>
using namespace std;
int main() {
  long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    if (m > n) {
      cout << "0" << endl;
      continue;
    }
    long long num = n / m, last = m % 10, temp1 = 0, temp2 = 0, comp, incomp,
              i = 1, sum = 0;
    while ((last * i) % 10 != 0) {
      temp1 += (last * i) % 10;
      i++;
    }
    comp = num / i;
    incomp = num % i;
    i = 1;
    while (incomp--) {
      temp2 += (last * i) % 10;
      i++;
    }
    sum = comp * temp1 + temp2;
    cout << sum << endl;
  }
  return 0;
}
