#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <queue>
using namespace std;
int a[10010],b[10010];
int gcd(int a,int b){
if(!b) return a;
return gcd(b,a%b);
}
int main( ){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<=n;i++){
cin>>a[i];
}
for(int i=0;i<=n;i++){
cin>>b[i];
}
int count1=0,count2=0;
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中的条件是a[i]
//cout<<count1<<" "<<count2<<endl;
if(count1>count2){
cout<<"infty"<<endl;
}
if(count1<count2){
cout<<"0 1"<<endl;
}
if(count1==count2){
int fac=gcd(a[count1],b[count2]);
printf("%d %d\n",a[count1]/fac,b[count2]/fac);
}
}
return 0;
}