#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long int t;
  cin >> t;
  while (t--) {
    unsigned long long int n, m;
    cin >> n >> m;
    if (n < m) {
      cout << 0 << "\n";
      continue;
    }
    int rec = m % 10;
    int r[10], cum[10];
    r[0] = rec;
    cum[0] = rec;
    for (int i = 1; i < 10; i++) {
      r[i] = (r[i - 1] + rec) % 10;
      cum[i] = (cum[i - 1] + r[i]);
    }
    unsigned long long int comp = n / m;
    unsigned long long int t1 = comp / 10, t2 = comp % 10;
    unsigned long long int sum = 0;
    sum += (t1 * cum[9]);
    if (t2 != 0) sum += cum[t2 - 1];
    cout << sum << "\n";
  }
  return 0;
}
