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