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