#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = long long unsigned;
using lf = long double;
void solve() {
  ll n, k;
  cin >> n >> k;
  ll nom = 2;
  while (n % nom != 0) {
    ++nom;
  };
  while (n % 2 != 0 && k > 0) {
    n += nom;
    nom = min(nom, n / nom);
    k--;
  }
  n += 2 * k;
  cout << n << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(20);
  cout << fixed;
  int tests;
  cin >> tests;
  while (tests--) {
    solve();
  }
}
