#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k, ans, temp, rem, sum = 0, temp_temp;
    cin >> n >> k;
    temp_temp = k;
    if (k > n)
      ans = 0;
    else {
      int num[10];
      for (int i = 0; i < 10; i++) {
        num[i] = temp_temp % 10;
        temp_temp = temp_temp + k;
        sum += num[i];
      }
      temp = n / k;
      rem = temp % 10;
      temp = temp / 10;
      ans = sum * temp;
      for (int i = 0; i < rem; i++) ans += num[i];
    }
    cout << ans << endl;
  }
}
