#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, k;
    scanf("%lld %lld", &n, &k);
    if (n % 2 == 0) {
      printf("%lld\n", (n + 2 * k));
    } else {
      bool found = false;
      for (int i = 3; i * i <= n; i++) {
        if (n % i == 0) {
          printf("%lld\n", (n + i + 2 * (k - 1)));
          found = true;
          break;
        }
      }
      if (!found) {
        printf("%lld\n", (2 * n + 2 * (k - 1)));
      }
    }
  }
  return 0;
}
