#include<iostream>
using namespace std;
typedef long long LL;
int get(int a, int b)//求最小公倍数
{
while (b)
{
int t = a % b;
a = b;
b = t;
}
return a;
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int a, b;
LL n;
scanf("%lld%d%d", &n, &a, &b);//a<b
int t = get(b, a);//最大公因数
LL t0 = (LL)a * b / (LL)t;//最小公倍数
LL res = ((n - 1) / t0) * a + 1;//即原先总长整除最小公倍数+起点0
printf("%lld\n", res);
}
return 0;
}