#include <stdio.h>
int main()
{
int a[10],b[10],c[10];
int n;
scanf("%d",&n);
while(n--)
{
int d[10]={0};
int num,i,max,k;
num=0;
max=0;
for(i=0;i<7;i++)
{
scanf("%d%d",&a[i],&b[i]);
c[i]=a[i]+b[i];
}
for(i=0;i<7;i++)
if(c[i]>8)
num++;
if(num==0)
printf("0
");
else if(num>=1)
{
for(i=0;i<7;i++)
{if(c[i]>8)
d[i]++;}
for(i=0;i<7;i++)
if(d[i]&&c[i]>max)
{
max=c[i];
k=i;
}
printf("%d
",k+1);
}
}
return 0;
}