#include <iostream>
#include <string>
using namespace std;
int main()
{
int T,n,t,t1,t2;
int count1=0,count2=0;
int a[1001],b[1001];
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<=n;i++)
{
scanf("%d",&b[i]);
}
for(int i=n;i>=0;i--)
{
if(a[i])
{
count1=i;
break;
}
}
for(int i=n;i>=0;i--)
{
if(b[i])
{
count2=i;
break;
}
}
if(count1>count2)
printf("infty\n");
else if(count1<count2)
printf("0 1\n");
else
{
t1=a[count1];
t2=b[count2];
if(t1<t2)
{
int temp;
temp=t1;
t1=t2;
t2=temp;
}
while(t2!=0)
{
t=t1%t2;
t1=t2;
t2=t;
}
printf("%d %d",a[count1]/t1,b[count2]/t1);
}
}
}