#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, i, s, a1, b1, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    if (n < m) {
      cout << "0\n";
      continue;
    }
    if (n == m)
      cout << n % 10 << "\n";
    else {
      long long int a[10] = {}, b[11] = {};
      for (i = 1; i <= 10; i++) {
        a[i - 1] = (m * i) % 10;
        b[i] += a[i - 1] + b[i - 1];
      }
      a1 = n / m;
      b1 = a1 % 10;
      a1 = a1 / 10;
      s = a1 * b[10] + b[b1];
      cout << s << "\n";
    }
  }
  return 0;
}
