#include "testlib.h"

#include <map>
using std::map;
int n;
map <int, int> *m;

void check( int *r, InStream &out, TResult pe, TResult wa ) {
  int ans[10];
  int was[1001];
  memset(was, 0, sizeof(was[0]) * 1001);
  for (int i = 0; i < 10; i++)
    ans[i] = out.readInt();
  out.seekEoln();
  for (int j = 0; j < 10; j++)
    r[j] = ans[j];
  for (int i = 0; i < n; i++) {
    int t = out.readInt();
    if (t == 0)
      continue;
    if (m[i].count(t) == 0)
      quitf(pe, "invalid competition (%d) for sportsman #%d", t, i + 1);
    if (was[t])
      quitf(wa, "competition #%d used by two or more sportsmen", t);
    was[t] = 1;
    ans[m[i][t]]--;
  }
  for (int j = 0; j < 10; j++)
    if (ans[j] != 0)
      quitf(wa, "wrong total number of medals (type=%d, r=%d, corr=%d)", j + 1, r[j], r[j] - ans[j]);
}

int main( int argc, char **argv ) {
  registerTestlibCmd(argc, argv);
  int ja[10], pa[10];
  n = inf.readInt();
  m = new map<int, int>[n];
  for (int i = 0; i < n; i++) {
    int k = inf.readInt();
    for (int j = 0; j < k; j++) {
      int a = inf.readInt();
      int b = inf.readInt();
      ensure(m[i].count(a) == 0);
      m[i][a] = b - 1 ;
    }
  }
  check(ja, ans, _fail, _fail);
  check(pa, ouf, _pe, _wa);
  for (int i = 0; i < 10; i++)
    if (ja[i] < pa[i])
      quitf(_fail, "[type=%d] jury has %d medals, contestant: %d", i + 1, ja[i], pa[i]);
    else if (ja[i] > pa[i])
      quitf(_wa, "[type=%d] jury has %d medals, contestant: %d", i + 1, ja[i], pa[i]);
  quitf(_ok, "ans: %d %d %d %d %d %d %d %d %d %d",
    ja[0], ja[1], ja[2], ja[3], ja[4], ja[5], ja[6], ja[7], ja[8], ja[9]);
}

