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