#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
void primeFactors(int n) {
  while (n % 2 == 0) {
    mp[2]++;
    if (mp.size() > 1) return;
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      mp[i]++;
      if (mp.size() > 1) return;
      n = n / i;
    }
  }
  if (n > 2) mp[n]++;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  primeFactors(n);
  auto i = mp.begin();
  n += i->first;
  k--;
  while (k--) {
    n += 2;
  }
  cout << n << "\n";
  mp.clear();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
