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