#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long x, y;
    cin >> x >> y;
    long long d = x / y;
    long long quotient = d / 10;
    long long remainder = d % 10;
    long long ans = 0;
    long long s = 0;
    for (int i = 1; i <= 10; i++) {
      s = s + (i * y) % 10;
    }
    ans += s * quotient;
    for (int i = 1; i <= remainder; i++) {
      ans += (y * i) % 10;
    }
    cout << ans << endl;
  }
}
