#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& o, const pair<T, U>& x) {
  o << "(" << x.first << ", " << x.second << ")";
  return o;
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& x) {
  o << "[";
  int b = 0;
  for (auto& a : x) o << (b++ ? ", " : "") << a;
  o << "]";
  return o;
}
template <typename T>
ostream& operator<<(ostream& o, const set<T>& x) {
  o << "{";
  int b = 0;
  for (auto& a : x) o << (b++ ? ", " : "") << a;
  o << "}";
  return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& o, const map<T, U>& x) {
  o << "{";
  int b = 0;
  for (auto& a : x) o << (b++ ? ", " : "") << a;
  o << "}";
  return o;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    set<long long> A;
    for (long long k = 1; k <= 10; k++) {
      A.insert((k * m) % 10);
    }
    long long s = 0;
    for (auto& x : A) {
      s += x;
    }
    long long x = n / m;
    long long ans = (x / (int)(A).size()) * s;
    long long r = (x % (int)(A).size());
    for (long long k = 1; k <= r; k++) {
      ans += (k * m) % 10;
    }
    cout << ans << endl;
  }
}
