点击查看代码
#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<queue>
#define int long long
#define inf 1e18
#define inc 0xcfcfcfcf
#define N 200007
#define M 500007
#define mod 1000000007
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
using namespace std;
inline int Read()
{
char ch=getchar();bool f=0;int x=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1)x=-x;return x;
}
int Get_gcd(int x,int y)
{
return y==0?x:Get_gcd(y,x%y);
}
int T=1,n;
int a[N],b[N];
bool Solve()
{
//freopen("test.in","r",stdin);
n=Read();
for(int i=1;i<=n;++i)
a[i]=Read(),b[i]=Read();
int gcd=0,lcm=1,ans=1;
for(int i=1;i<=n;++i)
{
gcd=Get_gcd(gcd,a[i]*b[i]);
lcm=lcm*b[i]/Get_gcd(lcm,b[i]);
if(gcd%lcm)
{
++ans;
gcd=a[i]*b[i];
lcm=b[i];
}
}
printf("%lld\n",ans);
return true;
}
signed main()
{
T=Read();
while(T--)
if(!Solve())
printf("-1\n");
return 0;
}
/*
1
4
20 3
6 2
14 5
20 7
*/