#include <bits/stdc++.h>
using namespace std;
void solve() {
  unsigned long long n, m;
  cin >> n >> m;
  int a[11];
  unsigned long long sum = 0, tsum = 0;
  for (int i = 1; i <= (10); ++i) {
    a[i] = ((m % 10) * i) % 10;
    sum += a[i];
  }
  unsigned long long div = n / m;
  unsigned long long rem = div % 10;
  tsum = sum * (div / 10);
  for (int i = 1; i <= rem; i++) tsum += a[i];
  cout << tsum << "\n";
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
