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