#include<bits/stdc++.h>

#define int long long

using namespace std;

vector v;

signed main()

{

int t,vec[] = {2,3,5,7,11,13,17,19,23,29},i;

cin>>t;

```
for(i=0;i<10;i++)
v.push_back(vec[i]);
while(t--)
{
int n,a,b,pt=0;
cin>>n>>a>>b;
if(a<=0&&n%2==0)
{
pt+=a;
n=1;
}
while(n%2==0)
{
if(a>0)
pt+=a;
n/=2;
}
if(b<=0&&n!=1)
{
pt+=b;
n=1;
}
else
{
while(n!=1)
{
for(i=0;i<10;i++)
{
if(n%v[i]==0)
{
pt+=b;
n/=v[i];
break;
}
}
}
}
cout<<pt<<endl;
}
return 0;
```

}