#include <bits/stdc++.h>
using namespace std;
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)(1e9) + 7;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
struct MinimumCostFlow {
  using Flow = long long;
  using Cost = double;
  const Cost kInfCost = INF;
  struct Edge {
    long long to, rev;
    Flow cap;
    Cost cost;
    Edge() {}
    Edge(long long to, long long rev, Flow cap, Cost cost)
        : to(to), rev(rev), cap(cap), cost(cost) {}
  };
  long long n;
  vector<vector<Edge>> g;
  vector<Cost> dist;
  vector<long long> prevv, preve;
  MinimumCostFlow(long long n) : n(n), g(n), dist(n), prevv(n), preve(n) {}
  void addArc(long long from, long long to, Flow cap, Cost cost) {
    g[from].emplace_back(to, (long long)g[to].size(), cap, cost);
    g[to].emplace_back(from, (long long)g[from].size() - 1, Flow(), -cost);
  }
  Cost minimumCostFlow(long long s, long long t, Flow f) {
    Cost total = Cost();
    while (f > 0) {
      fill(dist.begin(), dist.end(), kInfCost);
      dist[s] = 0;
      bool update = true;
      while (update) {
        update = false;
        for (long long v = 0; v < n; v++) {
          if (dist[v] == kInfCost) continue;
          for (long long i = 0; i < g[v].size(); i++) {
            Edge &e = g[v][i];
            if (e.cap > Flow() && 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] == kInfCost) return kInfCost;
      Flow d = f;
      for (long long v = t; v != s; v = prevv[v])
        d = min(d, g[prevv[v]][preve[v]].cap);
      f -= d;
      total += dist[t] * d;
      for (long long v = t; v != s; v = prevv[v]) {
        Edge &e = g[prevv[v]][preve[v]];
        e.cap -= d;
        g[v][e.rev].cap += d;
      }
    }
    return total;
  }
};
using Num = double;
using Vec = vector<Num>;
using Mat = vector<Vec>;
Vec gaussianElimination(Mat A, Vec b) {
  const long long n = A.size(), m = A[0].size();
  long long pi = 0, pj = 0;
  while (pi < n && pj < m) {
    for (long long i = pi + 1; i < n; i++)
      if (abs(A[i][pj]) > abs(A[pi][pj])) A[i].swap(A[pi]), swap(b[i], b[pi]);
    if (abs(A[pi][pj]) > 0) {
      Num d = A[pi][pj];
      for (long long j = 0; j < m; j++) A[pi][j] /= d;
      b[pi] /= d;
      for (long long i = pi + 1; i < n; i++) {
        Num k = A[i][pj];
        for (long long j = 0; j < m; j++) A[i][j] -= k * A[pi][j];
        b[i] -= k * b[pi];
      }
      pi++;
    }
    pj++;
  }
  for (long long i = pi; i < n; i++)
    if (abs(b[i]) > 0) return Vec();
  if (pi < m || pj < m) return Vec();
  for (long long j = m - 1; j >= 0; j--)
    for (long long i = 0; i < j; i++) b[i] -= b[j] * A[i][j];
  return b;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long T;
  cin >> T;
  cout << fixed << setprecision(10);
  while (T--) {
    long long N, s, t, F;
    cin >> N >> s >> t >> F;
    MinimumCostFlow mcf(N + N);
    Mat a(N, Vec(N));
    Vec c(N);
    for (long long i = (0); i < (N); i++)
      for (long long j = (0); j < (N + 1); j++) {
        if (j == N)
          cin >> c[i];
        else
          cin >> a[i][j];
      }
    Vec x = gaussianElimination(a, c);
    ;
    for (long long i = (0); i < (N); i++) {
      long long M;
      cin >> M;
      vector<long long> d(M);
      for (long long j = (0); j < (M); j++) {
        cin >> d[j];
      }
      vector<long long> f(M);
      for (long long j = (0); j < (M); j++) {
        cin >> f[j];
      }
      for (long long j = (0); j < (M); j++) {
        mcf.addArc(N + i, d[j], f[j], abs(x[i] - x[d[j]]));
      }
      mcf.addArc(i, N + i, INF, 0);
    }
    auto res = mcf.minimumCostFlow(s, N + t, F);
    if (res == INF)
      cout << "impossible" << endl;
    else
      cout << res << endl;
  }
  return 0;
}
