#include<stdio.h>
void gy(int a, int b)
{
int a1 = a, b1 = b;
int temp;
if(a < b)
{
temp = a;
a = b;
b = temp;
}
while(a - b != b)
{
temp = a - b;
a = b;
b = temp;
}
a1 = a1 / b;
b1 = b1 / b;
printf("%d %d", a1, b1);
return;
}
void lim(int *a1, int *b1, int n)
{
int a = 0 , b = 0;
int a_judge = 0, b_judge = 0;
for (int i = n - 1; a_judge == 0; i--)
{
if(a_judge == 0 && *(a1 + i) != 0)
{
a_judge = i;
a = *(a1 + i);
}
}
for (int i = n - 1; b_judge == 0; i--)
{
if(b_judge == 0 && *(b1 + i) != 0)
{
b_judge = i;
b = *(b1 + i);
}
}
if(a_judge > b_judge)
printf("infty");
else if(a_judge < b_judge)
printf("0 1");
else
gy(a, b);
}
int main()
{
int t = 0;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
int n = 0;
scanf("%d", &n);
n++; //From a[0] to a[n]
int a[n], b[n];
for (int j = 0; j < n; j++)
scanf("%d", &a[j]);
for (int j = 0; j < n; j++)
scanf("%d", &b[j]);
lim(a, b, n);
}
return 0;
}