#include <bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, m, r, l, k = 1, flag = 1, ans = 0, ctr = 0;
    cin >> n >> m;
    vector<long long int> sum(11, 0);
    for (int i = 1; i < 11; i++) {
      k = m * i;
      r = k % 10;
      ctr = ctr + r;
      sum[i] = ctr;
    }
    l = n / m;
    r = l % 10;
    l = l / 10;
    ans = (ctr * l) + sum[r];
    cout << ans << endl;
  }
  return 0;
}
