#include <bits/stdc++.h>
using namespace std;
int main() {
  long long test;
  cin >> test;
  while (test--) {
    long long n, k;
    cin >> n >> k;
    long long flag = 2;
    while (n % flag != 0) flag++;
    n = n + flag + (k - 1) * 2;
    cout << n << endl;
  }
}
