#include <bits/stdc++.h>
using namespace std;
bool plain(string str) {
  if (str.length() <= 1) return true;
  return str.back() == str.front() && plain(str.substr(1, str.length() - 2));
}
const int M = 2e5 + 6;
long long int n, m;
void solve() {
  cin >> n >> m;
  long long int x = n / m;
  long long int s = 0;
  for (long long int i = 1; i <= 9; ++i) {
    s += (m * i) % 10;
  }
  s *= (x / 10);
  x %= 10;
  for (long long int i = 1; i <= x; ++i) {
    s += (m * i) % 10;
  }
  cout << s << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
