#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, sum1 = 0, i, j;
    if (m > n) {
      cout << "0" << endl;
    } else {
      i = n / m;
      j = i % 10;
      for (int k = 1; k <= j; k++) {
        sum += (m * k) % 10;
      }
      if (i >= 10) {
        for (int k = 1; k <= 9; k++) sum1 += (m * k) % 10;
        sum1 = sum1 * (i / 10);
      }
      sum = sum + sum1;
      cout << sum << endl;
    }
  }
}
