#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int testcases = 1, n, m, sum, no, rem;
  int arr[11];
  cin >> testcases;
  while (testcases--) {
    cin >> n >> m;
    arr[1] = sum = m % 10;
    arr[10] = 0;
    for (int i = 2; i < 10; i++) {
      arr[i] = (m * i) % 10;
      sum += arr[i];
    }
    no = n / (m * 10);
    sum = sum * no;
    rem = (n / m - no * 10);
    for (int i = 1; i <= rem; i++) {
      sum += arr[i];
    }
    cout << sum << endl;
  }
  return 0;
}
