#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    scanf("%lld%lld", &n, &m);
    long long ans = 0;
    long long a[11];
    long long x = 0;
    for (int i = 1; i <= 10; i++) {
      a[i] = (m * i) % 10;
      x += a[i];
    }
    if (n < m) {
      cout << "0" << endl;
      continue;
    } else if (n == m) {
      cout << m % 10 << endl;
      continue;
    } else {
      long long xx = n / m;
      long long yy = xx % 10;
      xx /= 10;
      ans += (long long)(x * xx);
      for (int i = 1; i <= yy; i++) ans += a[i];
      cout << ans << endl;
    }
  }
  return 0;
}
