#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005, MOD = 998244353;
const long long inf = 5e18;
int arr[2 * MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int q;
  cin >> q;
  while (q--) {
    long long n, m;
    long long a = 0;
    cin >> n >> m;
    long long d = m % 10;
    for (int i = 1; i <= 9; i++) a += ((d * i) % 10);
    n /= m;
    int rem = n % 10;
    n /= 10;
    a *= n;
    if (rem)
      for (int i = 1; i <= rem; i++) a += ((d * i) % 10);
    cout << a << "\n";
  }
}
