#include <bits/stdc++.h>
using namespace std;
int smallestDivisor(int n) {
  if (n % 2 == 0) return 2;
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return i;
  }
  return n;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long temp = smallestDivisor(n);
    cout << n + temp + 2 * (k - 1) << endl;
  }
  return 0;
}
