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