#include <bits/stdc++.h>
using namespace std;
long long a[150500];
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  vector<long long> ans;
  for (int f = 0; f < t; f++) {
    long long n, m;
    cin >> n >> m;
    vector<long long> l;
    l.push_back(m % 10);
    for (long long i = m + m; l[0] != i % 10; i += m) l.push_back(i % 10);
    long long c = n / m / l.size() * accumulate(l.begin(), l.end(), 0);
    for (int i = 0; i < n / m % l.size(); i++) c += l[i];
    ans.push_back(c);
  }
  for (auto i : ans) cout << i << endl;
  return 0;
}
