#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T, N, K;
  cin >> T;
  for (int t = 1; t <= T; ++t) {
    cin >> N >> K;
    int n = N;
    int div = 0;
    int k = 0;
    while (k < K && div != 2) {
      int i = 2;
      while (i <= n) {
        if (n % i == 0) {
          div = i;
          break;
        }
        i++;
      }
      n += div;
      k++;
    }
    cout << n + (K - k) * div << endl;
  }
  return 0;
}
