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