#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int div = 2;
    while (n % div != 0) {
      div++;
    }
    cout << n + div + 2 * (k - 1) << endl;
  }
  return 0;
}
