#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long n, m;
    cin >> n >> m;
    long long ans;
    if (n < m) {
      ans = 0;
    } else if (n == m)
      ans = m % 10;
    else {
      int d = m % 10;
      int rem[10];
      rem[0] = 0;
      for (int i = 1; i < 10; ++i) {
        rem[i] = (i * d) % 10 + rem[i - 1];
      }
      long long tot = n / m;
      ans = rem[tot % 10] + (tot / 10) * rem[9];
    }
    cout << ans << endl;
  }
}
