#include <bits/stdc++.h>
using namespace std;
int q;
long long n, m;
vector<long long> a;
void solve() {
  a.clear();
  cin >> n >> m;
  int cur = 0;
  bool found = false;
  while (found == false) {
    long long tmp = m * (cur + 1);
    if (not a.empty())
      for (int i = 0; i <= a.size() - 1; i++)
        if (tmp % 10 == a[i] % 10) found = true;
    if (not found) {
      cur++;
      a.push_back(m * cur);
    }
  }
  long long sl = (n / m) / (long long)cur;
  long long s = 0;
  for (int i = 0; i < a.size(); i++) s += a[i] % 10;
  long long res = sl * s;
  int du = (n / m) % cur;
  for (int i = 0; i < du; i++) res += a[i] % 10;
  cout << res << endl;
}
int main() {
  cin >> q;
  for (int t = 1; t <= q; t++) {
    solve();
  }
}
