#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, x;
    cin >> a >> b;
    x = a;
    for (long long i = 2; i <= a; i++) {
      if (a % i == 0) {
        x += i;
        break;
      }
    }
    x += (b - 1) * 2;
    cout << x << endl;
  }
  return 0;
}
