#include <bits/stdc++.h>
using namespace std;
const long long int big = 10e15 + 11;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, sum = 0, m, ans = 0;
    cin >> n >> m;
    for (int i = 1; i <= 10; i++) {
      sum += (i * m) % 10;
    }
    long long int ace = n / (m * 10);
    ans = ace * sum;
    ace = ace * (m * 10);
    ace += m;
    while (ace <= n) {
      ans += (ace % 10);
      ace += m;
    }
    cout << ans << "\n";
  }
  return 0;
}
