#include <bits/stdc++.h>
using namespace std;
inline void get_arr(vector<int> &arr, int n) {
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    arr.push_back(a);
  }
}
inline void print_arr(vector<int> &arr, int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "\n";
  ;
}
bool is_prime(long long n) {
  bool flag = true;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return (flag);
}
long long div(long long n) {
  long long i = 2;
  while (n % i != 0) i++;
  return (i);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n % 2 == 0)
      n += 2 * k;
    else {
      n += div(n);
      n += 2 * (k - 1);
    }
    cout << n << "\n";
    ;
  }
  return (0);
}
