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