#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k, minn = INT_MAX;
    cin >> n >> k;
    if (n % 2 == 0) {
      cout << (n + 2 * k) << endl;
    } else {
      long long int minn = INT_MAX;
      long long int j = INT_MAX;
      for (long long int i = 3; i <= sqrt(n); i++) {
        if (n % i == 0) {
          if (n / i == i) {
            minn = min(minn, i);
          } else {
            minn = min(minn, min(i, n / i));
          }
        }
      }
      if (minn == j) {
        n += n;
        cout << n + 2 * (k - 1) << endl;
      } else {
        cout << (n + minn + 2 * (k - 1)) << endl;
      }
    }
  }
}
