#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    long long k;
    cin >> n >> k;
    if (n % 2 != 0) {
      for (int i = 3; i <= n; i += 2) {
        if (n % i == 0) {
          n += i;
          k--;
          break;
        }
      }
    }
    cout << n + 2 * k << '\n';
  }
}
