#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n , k ;
int t;
cin>>t;
while(t--)
{
cin>>n>>k;
int a1;
for(int i=2;i<=n;i++)
{
if(n%i==0)
{
a1=i;break;
}
}
a1+=n;
cout<<a1+(k-1)*2<<endl;
}
}