#include <bits/stdc++.h>
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    long long n, m, ans;
    int k;
    scanf("%lld%lld", &n, &m);
    ans = 0;
    for (k = 0; k <= 10; k++)
      ans += (n + (10 - k) * m) / (m * 10) * (m * k % 10);
    printf("%lld\n", ans);
  }
  return 0;
}
