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