#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int sum = 0;
    for (long long int i = 1; i <= 10; i++) {
      long long int mul = i * m;
      sum += mul % 10;
    }
    long long int m1 = m * 10;
    long long int div = n / m1;
    long long int mod = n % m1;
    long long int ans = div * sum;
    long long int div1 = mod / m;
    for (long long int i = 1; i <= div1; i++) {
      ans += (m * i) % 10;
    }
    cout << ans << endl;
  }
}
