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