#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    long long n, m;
    cin >> n >> m;
    if (n < m) {
      cout << 0 << '\n';
      continue;
    }
    vector<long long> a(10);
    long long val = m, sum = 0;
    for (long long i = 0; i < 10; ++i) {
      a[i] = val % 10;
      val += m;
      sum += a[i];
    }
    long long l = n / m;
    long long x = l % 10;
    long long y = l / 10;
    long long res = sum * y;
    for (int i = 0; i < x; ++i) res += a[i];
    cout << res << '\n';
  }
  return 0;
}
