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