#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int x = n / m;
    long long int a[11];
    long long int sum = 0;
    for (long long int i = 1; i <= 10; i++) {
      sum += (m * i) % 10;
    }
    long long int r = x / 10;
    long long int y = x % 10;
    sum = sum * r;
    for (long long int i = 1; i <= y; i++) {
      sum += (m * i) % 10;
    }
    cout << sum << "\n";
  }
  return 0;
}
