#include<bits/stdc++.h>
#define N 10000
using namespace std;
int T,n;
int a[N],b[N];
int gcd(int a,int b){return b == 0 ? a : gcd(b,a % b);}
int main(){
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] && !b[i]) continue;
if(!a[i]){
printf("0 1\n");
}
else if(!b[i]){
printf("infty\n");
}
else{
int tmp = gcd(a[i],b[i]);
printf("%d %d\n",a[i] / tmp,b[i] / tmp);
}
break;
}
}
return 0;
}