#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n, x, t;
cin >> n >> x >> t;
if(x <= (2*n-2)*t)
cout << 4*n*t << '\n';
else{
int ret=x+2*t+2*n*t;
if(x-(2*n-2)*t <= t)
ret=min(ret,x + 2*n*t);
// cout << x + 2*n*t << '\n';
else{
if(x-2*n*t <= 0)
ret=min(ret,4*n*t+t)
// ret=min(ret,(4*n+1)*t);
// cout << (4*n+1)*t << '\n';
else
ret=min(ret,x + 2*n*t+t);
// cout << x + (2*n+1)*t << '\n';
}
cout<< ret<<"\n";
}
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);std::cout.tie(0);
int t=1;
std::cin >>t;
while(t--){
solve();
}
return 0;
}