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