#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a, b, x;
  cin >> b;
  for (int j = 0; j < b; j++) {
    cin >> n >> k;
    a = sqrt(n);
    x = n;
    for (int i = 2; i <= a; i++) {
      if (n % i == 0) {
        n = n + i;
        break;
      }
    }
    if (x == n) n = n * 2;
    n = n + (2 * (k - 1));
    cout << n << endl;
  }
  return 0;
}
