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