#include <bits/stdc++.h>
using namespace std;
const int dyo[] = {0, 0, -1, -1, -1, 0, 1, 1, 1};
const int dxo[] = {0, -1, -1, 0, 1, 1, 1, 0, -1};
const int dyk[] = {0, -1, -2, -2, -1, 1, 2, 2, 1};
const int dxk[] = {0, -2, -1, 1, 2, 2, 1, -1, -2};
const int dy[] = {0, 0, -1, 0, 1};
const int dx[] = {0, -1, 0, 1, 0};
const double pi = acos(-1.0);
const int N = 10005;
int q;
long long int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> n >> m;
    vector<int> pattern;
    unordered_map<int, bool> vis;
    int sum = 0;
    int i = 1;
    long long int temp = 0;
    while (1) {
      temp += m;
      temp %= 10;
      if (vis[temp]) break;
      vis[temp] = 1;
      pattern.push_back(temp);
      sum += temp;
    }
    long long int hasil = (n / m) / (int)pattern.size();
    long long int sisa = (n / m) - (hasil * (int)pattern.size());
    long long int ans = hasil * sum;
    for (int i = 0; i <= (int)sisa - 1; i++) ans += (long long int)pattern[i];
    cout << ans << '\n';
  }
}
