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