#include "testlib.h"

#define MAXT 1000
#define MAXN 5000
#define MAXR ((int)1e9)

using namespace std;

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

    int t = inf.readInt(1, MAXT, "t"), nsum = 0;
    inf.readEoln();
    for (int tn = 0; tn < t; tn++) {
      setTestCase(tn + 1);
      int n = inf.readInt(1, MAXN, "N");
      nsum += n;
      ensure(nsum <= MAXN);
      inf.readSpace();
      int a = inf.readInt(1, MAXR, "A");
      inf.readSpace();
      int b = inf.readInt(1, MAXR, "B");
      inf.readEoln();
      set <pair <int, int>> S;
      for (int i = 0; i < n; i++) {
        int ca = inf.readInt(1, a, "suit");
        inf.readSpace();
        int cb = inf.readInt(1, b, "card");
        inf.readEoln();
        ensure(S.find(make_pair(ca, cb)) == S.end());
        S.insert(make_pair(ca, cb));
      }
    }
    inf.readEof();

    return 0;
}
