#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
void solve() {
  long long m, k;
  cin >> m >> k;
  for (int i = 2; i <= m; i++) {
    if (m % i == 0) {
      m += i;
      k--;
      break;
    }
  }
  if (m % 2 == 0 && k > 0) {
    cout << m + (k * 2) << endl;
    return;
  }
  cout << m << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
