#include <bits/stdc++.h>
using namespace std;
long long int n, m, ans;
bool ten[10];
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> m;
    long long int b = m, sten[11];
    sten[0] = 0;
    for (int i = 0; i < 10; i++) {
      b %= 10;
      sten[i + 1] = b + sten[i];
      b += m;
    }
    n /= m;
    ans = (n / 10 * sten[10] + sten[n % 10]);
    cout << ans << endl;
  }
  return 0;
}
