#include <bits/stdc++.h>
using namespace std;
long long a[15];
long long n, p, cnt, cnt1, cnt2, ans, t, m;
int main() {
  cin >> t;
  while (t--) {
    ans = 0, cnt2 = 0;
    cin >> n >> m;
    cnt = n / m;
    cnt1 = m % 10;
    for (int i = 1; i <= 10; i++) {
      a[i] = (cnt1 * i) % 10;
      cnt2 += a[i];
    }
    ans = (cnt / 10) * cnt2;
    n = cnt % 10;
    for (int i = 1; i <= n; i++) {
      ans += a[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
