#include "my_testlib.h"

#include <cmath>

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

typedef long long ll;
typedef long double dbl;

const int N = 1000;
const int D = 10;
const int M = 3;
const dbl eps = 1e-9;
                  
int n, d, a[N][D];
int cc, u[N];
int num, id[M];
dbl b[M][D];

void readInput( InStream &in )
{
  n = in.readInt(1, N);
  d = in.readInt(1, D);
  forn(i, n)
    forn(j, d)
      a[i][j] = inf.readInt();
}

void add( int *a )
{
  forn(i, d)
    b[num][i] = a[i];
  forn(i, num)
    if (fabs(b[num][id[i]]) > eps)
    {
      dbl koef = b[num][id[i]] / b[i][id[i]];
      forn(j, d)
        b[num][j] -= koef * b[i][j];
      b[num][id[i]] = 0;
    }
  forn(i, d)
    if (fabs(b[num][i]) > eps)
      id[num++] = i, i = d;
}

int checkOutput( InStream &out )
{
  int k = out.readInt();
  cc++, num = 0;
  forn(i, k)
  {
    int x = out.readInt(1, n) - 1;
    if (u[x] == cc)
      out.quitf(_wa, "vector #%d is used twice", x + 1);
    u[x] = cc;
    add(a[x]);
    if (num >= M)
      out.quitf(_wa, "first %d vectors already raise 3D subspace", i + 1);
  }
  return k;
}

int main(int argc, char *argv[])
{
  registerTestlibCmd(argc, argv);

  readInput(inf);

  int ja = checkOutput(ans);
  int ca = checkOutput(ouf);

  if (ca != ja)
    quitf(ca > ja ? _fail : _wa, "Contestant says %d, jury say %d", ca, ja);
  quitf(_ok, "OK (%d of %d)", ja, n);
  return 0;
}
