#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t, n, m, a, nl, ml;
  cin >> t;
  long long int arr[10];
  while (t--) {
    cin >> n >> m;
    nl = n % 10;
    ml = m % 10;
    for (long long int i = 0; i < 10; i++) arr[i] = ((i + 1) * ml) % 10;
    long long int sum = 0;
    sum = accumulate(arr, arr + 10, 0LL);
    n = n / m;
    sum = n / 10 * sum;
    for (long long int i = 0; i < n % 10; i++) sum += arr[i];
    cout << sum << endl;
  }
}
