#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t > 0) {
    long long int n, m, i;
    cin >> n >> m;
    long long int k = (long long int)(n / m);
    int cycle[10];
    int sum = 0;
    for (i = 0; i < 10; i++) {
      cycle[i] = (m * (i + 1)) % 10;
      sum = sum + cycle[i];
    }
    long long int ans = 0;
    for (i = 0; i < k % 10; i++) {
      ans = ans + cycle[i];
    }
    ans = ans + (((long long int)(k / 10)) * sum);
    cout << ans << "\n";
    t--;
  }
}
