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