#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long p = -1;
    for (long long i = 2; i <= n; i++) {
      if (n % i == 0) {
        p = i;
        break;
      }
    }
    cout << n + p + 2 * (k - 1) << endl;
  }
}
