#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long sum = 0, cyl = 0;
    long long k = (n / m);
    for (int i = 1; i <= 10; ++i) {
      cyl += (m * i) % 10;
    }
    sum = (k / 10) * cyl;
    cyl = 0;
    for (int i = 1; i <= k % 10; ++i) {
      cyl += m * (i) % 10;
    }
    cout << sum + cyl << endl;
  }
  return 0;
}
