#include<cmath>
#include<queue>
#include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-8;

const int N_MAX=100;

bool Gauss_Jordan(int n,const double A[N_MAX][N_MAX],const double *b,double *x){
	static double B[N_MAX][N_MAX+1];
	rep(i,n){
		rep(j,n) B[i][j]=A[i][j];
		B[i][n]=b[i];
	}

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(B[j][i])>abs(B[piv][i])) piv=j;
		rep(j,n+1) swap(B[i][j],B[piv][j]);

		if(abs(B[i][i])<EPS) return false;

		for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
	}

	rep(i,n) x[i]=B[i][n];
	return true;
}

const int V_MAX=101;
const int CAPA_INF=1<<29;
const double COST_INF=1e77;

template<class capa_t,class cost_t>
struct edge{
	int v,rev;
	capa_t capa;
	cost_t cost;
	capa_t flow;
};

template<class capa_t,class cost_t>
void add_directed_edge(vector< edge<capa_t,cost_t> > *G,int u,int v,capa_t capa,cost_t cost){
	G[u].push_back((edge<capa_t,cost_t>){v,G[v].size()  ,capa, cost,0});
	G[v].push_back((edge<capa_t,cost_t>){u,G[u].size()-1,   0,-cost,0});
}

template<class capa_t,class cost_t>
pair<capa_t,cost_t> augment(int n,vector< edge<capa_t,cost_t> > *G,int s,int t,cost_t *pot){
	static int pre[V_MAX];
	static cost_t d[V_MAX];
	rep(u,n) d[u]=(u==s?0:COST_INF);

	// Dijkstra
	bool ok=false;
	priority_queue< pair<cost_t,int> > Q; Q.push(make_pair(0,s));
	while(!Q.empty()){
		int u=Q.top().second;
		cost_t cost=-Q.top().first; Q.pop();

		if(cost<d[u]-EPS) continue;
		if(u==t) ok=true;

		rep(i,G[u].size()){
			edge<capa_t,cost_t> &e=G[u][i];
			cost_t cost2=cost+e.cost+pot[u]-pot[e.v];
			if(e.capa-e.flow>0 && cost2<d[e.v]-EPS){
				d[e.v]=cost2;
				pre[e.v]=e.rev;
				Q.push(make_pair(-cost2,e.v));
			}
		}
	}

	if(!ok) return make_pair(0,0);

	capa_t water=CAPA_INF;
	for(int v=t;v!=s;){
		edge<capa_t,cost_t> &e1=G[v][pre[v]];
		edge<capa_t,cost_t> &e2=G[e1.v][e1.rev];
		water=min(water,e2.capa-e2.flow);
		v=e1.v;
	}

	cost_t cost=0;
	for(int v=t;v!=s;){
		edge<capa_t,cost_t> &e1=G[v][pre[v]];
		edge<capa_t,cost_t> &e2=G[e1.v][e1.rev];
		e1.flow-=water;
		e2.flow+=water;
		cost+=water*e2.cost;
		v=e1.v;
	}

	rep(u,n) pot[u]+=d[u];

	return make_pair(water,cost);
}

template<class capa_t,class cost_t>
pair<capa_t,cost_t> primal_dual(int n,vector< edge<capa_t,cost_t> > *G,int s,int t){
	static cost_t pot[V_MAX];
	rep(u,n) pot[u]=0;

	capa_t ans1=0;
	cost_t ans2=0;
	while(1){
		pair<capa_t,cost_t> tmp=augment(n,G,s,t,pot);
		if(tmp.first==0) break;
		ans1+=tmp.first;
		ans2+=tmp.second;
	}
	return make_pair(ans1,ans2);
}

int main(){
	int T; scanf("%d",&T);
	while(T--){
		int n,s,t,F; scanf("%d%d%d%d",&n,&s,&t,&F);

		static double A[N_MAX][N_MAX],b[N_MAX],x[N_MAX];
		rep(i,n){
			rep(j,n) scanf("%lf",A[i]+j);
			scanf("%lf",b+i);
		}
		Gauss_Jordan(n,A,b,x);

		vector< edge<int,double> > G[V_MAX];
		rep(u,n){
			int m; scanf("%d",&m);
			int dest[100],capa[100];
			rep(i,m) scanf("%d",dest+i);
			rep(i,m) scanf("%d",capa+i);
			rep(i,m) add_directed_edge(G,u,dest[i],capa[i],abs(x[u]-x[dest[i]]));
		}
		add_directed_edge(G,t,n,F,0.0);

		pair<int,double> ans=primal_dual(n+1,G,s,n);
		if(ans.first<F) puts("impossible"); else printf("%.9f\n",ans.second);
	}

	return 0;
}

Measured memory_bytes: 2140