#include <bits/stdc++.h>
using namespace std;
int ar[100001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    long long val = n / m;
    int a = m % 10, cnt = 0;
    ar[cnt++] = a;
    int b = 2;
    while ((a * b) % 10 != a) {
      ar[cnt++] = (a * b) % 10;
      b++;
    }
    long long sum = 0;
    for (int i = 0; i < cnt; i++) sum += ar[i];
    long long ans = 0;
    ans += sum * (val / cnt);
    for (int i = 0; i < (val % cnt); i++) ans += ar[i];
    cout << ans << endl;
  }
}
