#include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937 rng(1234);
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int fr = -1;
    for (int i = 2; i <= n; ++i) {
      if (n % i == 0) {
        fr = i;
        break;
      }
    }
    n += fr + (k - 1) * 2;
    cout << n << "\n";
  }
}
