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