#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    long long n, m;
    cin >> n >> m;
    long long ans = 0;
    long long tim = n / m;
    long long cyc = 0;
    if (tim >= 10) {
      for (int i = 1; i <= 10; ++i) {
        cyc += m * i % 10;
      }
      ans += tim / 10 * cyc;
    }
    long long rest = tim % 10;
    for (int i = 1; i <= rest; ++i) ans += m * i % 10;
    cout << ans << endl;
  }
  return 0;
}
