#include <bits/stdc++.h>
using namespace std;
const int NUM = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int num_tests = 1;
  cin >> num_tests;
  while (num_tests-- > 0) {
    long long int n, m;
    cin >> n >> m;
    long long int div = n / m;
    long long int sum[10];
    sum[0] = 0;
    for (int i = 1; i < 10; i++) sum[i] = sum[i - 1] + (i * m) % 10;
    long long int ans = (div / 10) * sum[9];
    ans += sum[(n / m) % 10];
    cout << ans << "\n";
  }
}
