#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  unsigned long long int q;
  cin >> q;
  while (q--) {
    unsigned long long int n, m, my[11] = {0};
    cin >> n >> m;
    for (int i = 1; i <= 10; i++) my[i] = (m * i) % 10, my[i] += my[i - 1];
    cout << (n / m / 10) * (my[10]) + my[n / m % 10] << "\n";
  }
  return 0;
}
