#include <stdio.h>
#include <stdlib.h>
int simpli(int m,int n)
{
int p = m,q = n;
int rem;
while(n>0)
{
rem = m%n;
m = n;
n = rem;
}
printf("%d %d",p/m,q/m);
}
int main()
{
int m,i,j;
scanf("%d",&m);
int *b1[100],*b2[100];
int b[100];
for(i = 0; i<m; i++)
{
scanf("%d",&b[i]);
b1[i] = (int *)calloc(b[i]+1,sizeof(int));
b2[i] = (int *)calloc(b[i]+1,sizeof(int));
for(j = 0; j<=b[i]; j++)
scanf("%d",b1[i]+j);
for(j = 0; j<=b[i]; j++)
scanf("%d",b2[i]+j);
//for(j = 0; j<=b[i]; j++)
// printf("%d",*(b1[i]+j));
//for(j = 0; j<=b[i]; j++)
// printf("%d",*(b2[i]+j));
}
for(i = 0; i<m; i++)
{
j = b[i];
while(0==*(b1[i]+j)&&0==*(b2[i]+j))
j--;
if(0==*(b1[i]+j))
printf("0 1");
else if(0==*(b2[i]+j))
printf("infty");
else
{
simpli(*(b1[i]+j),*(b2[i]+j));
}
printf("\n");
}
for(i = 0;i<m;i++)
{
free(b1[i]);
free(b2[i]);
}
return 0;
}