#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n, k;
    cin >> n >> k;
    int64_t i;
    for (i = 2; i <= n; i++) {
      if (n % i == 0) {
        break;
      }
    }
    int64_t ans = n + i + (k - 1) * 2;
    cout << ans << endl;
  }
  return 0;
}
