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