#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long x = n / m, ans = 0;
  vector<long long> v;
  for (long long i = 1; i <= 10; i++) v.push_back((i * m) % 10);
  for (long long i = 0; i < 10; i++) ans += v[i];
  ans *= x / 10;
  for (long long i = 0; i < x % 10; i++) ans += v[i];
  cout << ans << "\n";
  return;
}
int32_t main() {
  long long test;
  cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}
