#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
struct edge {
  int to, cap, rev;
  double cost;
  edge(int to, int cap, int rev, double cost)
      : to(to), cap(cap), rev(rev), cost(cost) {}
};
vector<edge> G[300];
double dist[300];
int prevv[300], preve[300];
void add_edge(int from, int to, int cap, double cost) {
  G[from].push_back(edge(to, cap, G[to].size(), cost));
  G[to].push_back(edge(from, 0, G[from].size() - 1, -cost));
}
double min_cost_flow(int s, int t, int f) {
  double res = 0;
  while (f > 0) {
    fill(dist, dist + 300, 1e9);
    dist[s] = 0;
    bool update = true;
    while (update) {
      update = false;
      for (int v = 0; v < 300; v++) {
        if (dist[v] == 1e9) continue;
        for (int i = 0; i < (int)G[v].size(); i++) {
          edge &e = G[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
            dist[e.to] = dist[v] + e.cost;
            prevv[e.to] = v;
            preve[e.to] = i;
            update = true;
          }
        }
      }
    }
    if (dist[t] == 1e9) {
      return -1;
    }
    int d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * dist[t];
    for (int v = t; v != s; v = prevv[v]) {
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
vector<double> gauss_jordan(const vector<vector<double> > &A,
                            const vector<double> &b) {
  int n = A.size();
  vector<vector<double> > B(n, vector<double>(n + 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      B[i][j] = A[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    B[i][n] = b[i];
  }
  for (int i = 0; i < n; i++) {
    int pivot = i;
    for (int j = i; j < n; j++) {
      if (abs(B[j][i]) > abs(B[pivot][i])) {
        pivot = j;
      }
    }
    swap(B[i], B[pivot]);
    if (abs(B[i][i]) < EPS) return vector<double>();
    for (int j = i + 1; j <= n; j++) {
      B[i][j] /= B[i][i];
    }
    for (int j = 0; j < n; j++) {
      if (i != j) {
        for (int k = i + 1; k <= n; k++) {
          B[j][k] -= B[j][i] * B[i][k];
        }
      }
    }
  }
  vector<double> x(n);
  for (int i = 0; i < n; i++) {
    x[i] = B[i][n];
  }
  return x;
}
void init() {
  for (int i = 0; i < 300; i++) {
    G[i].clear();
  }
}
int main() {
  int Tc;
  cin >> Tc;
  while (Tc--) {
    int N, s, t, F;
    init();
    cin >> N >> s >> t >> F;
    vector<vector<double> > a(N, vector<double>(N));
    vector<double> c(N);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        cin >> a[i][j];
      }
      cin >> c[i];
    }
    vector<double> res = gauss_jordan(a, c);
    for (int i = 0; i < N; i++) {
      int M, d[N], f;
      cin >> M;
      for (int j = 0; j < M; j++) {
        cin >> d[j];
      }
      for (int j = 0; j < M; j++) {
        cin >> f;
        add_edge(i, d[j], f, abs(res[i] - res[d[j]]));
      }
    }
    double ans = min_cost_flow(s, t, F);
    if (ans == -1) {
      printf("impossible\n");
    } else {
      printf("%.6f\n", ans);
    }
  }
  return 0;
}
