#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n % 2 == 0) {
      cout << n + k * 2 << endl;
    } else {
      vector<long long> x;
      long long N = n;
      for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) x.push_back(i);
        if (n % i == 0) {
          n /= i;
        }
      }
      if (n >= 2) {
        x.push_back(n);
      }
      long long temp;
      for (int i = 0; i < x.size(); i++)
        if (x[i] % 2 == 1) {
          temp = x[i];
          break;
        }
      N += temp;
      k--;
      cout << N + k * 2 << endl;
    }
  }
}
