#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b;
  cin >> a >> b;
  long long bmod = b % 10, s = 0;
  for (long long i = 1; i < 10; ++i) {
    s += (bmod * i) % 10;
  }
  long long rem = 0;
  for (long long i = 1; b * i <= a % (b * 10); ++i) {
    rem += (i * bmod) % 10;
  }
  cout << s * (a / b / 10) + rem << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
