#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  cin >> test;
  while (test--) {
    long long n, m;
    cin >> n >> m;
    int ans[11][11];
    for (long long i = 0; i < (11); ++i)
      for (long long j = 0; j < (11); ++j) ans[i][j] = 0;
    for (int i = 1; i < 11; i++) {
      for (int j = 1; j < 11; j++) {
        ans[i][j] = ans[i][j - 1] + (i * j) % 10;
      }
    }
    cout << ((n / m - (n / m) % 10) / 10) * ans[m % 10][10] +
                ans[m % 10][((n / m) % 10)]
         << "\n";
  }
}
