#include<bits/stdc++.h>
using namespace std;
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int maxn=1e5+100;
const int lz=0;
const ll INF=1e18;
int c[5],n;
double p[20][5];
double dfs(int cur){
if(cur==n) return 1.0;
double ret=0;
rep(i,0,5){
if(c[i]==0) continue;
if(p[cur][i]==0) continue;
c[i]--;
ret+=p[cur][i]*dfs(cur+1);
c[i]++;
}
return ret;
}
int main(){/*
freopen("d://in.txt","r",stdin);
freopen("d://out.txt","w",stdout);*/
int t;scanf("%d",&t);
while(t--){
scanf("%d",&n);
rep(i,0,5) scanf("%d",&c[i]);
rep(i,0,n) rep(j,0,5) scanf("%lf",&p[i][j]);
double ansp=0,tot=0;
int idx=-1;
rep(i,0,5){
if(c[i]==0) continue;
if(p[0][i]==0) continue;
c[i]--;
double tmp=p[0][i]*dfs(1);
///printf("%lf %lf\n",p[0][i],tmp);
tot+=tmp,c[i]++;///坑点,,,最后还要选中朋友的礼物
if(tmp/c[i]>ansp) ansp=tmp/c[i],idx=i;
}
printf("%d %.3f\n",idx+1,ansp/tot);
}
return 0;
}