#include <bits/stdc++.h>
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long MOD1 = 998244353;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
using namespace std;
long long power(unsigned long long x, unsigned long long y) {
  unsigned long long res = 1;
  while (y > 0) {
    if (y & 1) res = (unsigned long long)(res * x);
    y = y >> 1;
    if (x <= 100000000) x = (unsigned long long)(x * x);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    if (n % 2 == 0) {
      n = n + k * 2;
      cout << n << '\n';
    } else {
      long long sum = 0;
      for (int i = 3; i <= n; i += 2) {
        if (n % i == 0) {
          sum = i;
          break;
        }
      }
      sum += n;
      sum += 2 * (k - 1);
      cout << sum << '\n';
    }
  }
  return 0;
}
