#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long int divisor(long long int N) {
  if (N % 2 == 0) return 2;
  for (auto i = 3; i <= sqrt(N); i += 2) {
    if (N % i == 0) return i;
  }
  return N;
}
void solve() {
  long long int N, K;
  cin >> N >> K;
  while (K--) {
    if (!(N & 1)) {
      N += 2 * K;
      K = 0;
    }
    N = divisor(N) + N;
  }
  cout << N << "\n";
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
