#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    unsigned long long int z, y, x, i, n, m, cu1 = 0;
    cin >> n >> m;
    x = n / m;
    y = x / 10;
    z = x % 10;
    for (i = 1; i < 10; i++) {
      cu1 = cu1 + (m * i) % 10;
    }
    cu1 = cu1 * y;
    for (i = 1; i <= z; i++) {
      cu1 = cu1 + (m * i) % 10;
    }
    cout << cu1 << endl;
  }
}
