#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define srt(v) sort(v.begin(), v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define pb push_back
int chk(int n)
{
vector<int>samp;
int p = 1;
while(p < n)
{
if(n%p == 0)
{
samp.push_back(p);
}
p++;
}
return samp.back();
}
void solve(){
int n, m, k; cin >> n >> m >> k;
for(int i=0; i<k; i++){
int x;
if((n+m)%2==0){
x=m-1;
}else{
x=m;
}
n+=x;
n/=chk(n);
}
cout << n << endl;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t; cin >> t;
while(t--){
solve();
}
}