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