#include <bits/stdc++.h>
#include "testlib.h"

using namespace std;

bool readAns(InStream& in, int n, vector<int> u, vector<int> v) {
  vector<int> a(n);
  a[0] = in.readInt(-1, n, "a_1");
  if (a[0] == -1) {
    return false;
  }
  if (a[0] == 0) {
    in.quitf(_wa, "invalid vertex: 0");
  }
  vector<int> pos(n + 1, -1);
  pos[a[0]] = 0;
  for (int i = 1; i < n; i++) {
    a[i] = in.readInt(1, n, "a_" + to_string(i + 1));
    if (pos[a[i]] != -1) {
      in.quitf(_wa, "duplicate vertex: %d", a[i]);
    }
    pos[a[i]] = i;
  }
  int m = int(u.size());
  int k = 0;
  for (int i = 0; i < m; i++) {
    if (pos[u[i]] < pos[v[i]]) {
      k += 1;
    }
  }
  if (2 * k < m) {
    in.quitf(_wa, "not enough good edges: m = %d, k = %d", m, k);
  }
  return true;
}

int main(int argc, char* argv[]) {
  registerTestlibCmd(argc, argv);
  int t = inf.readInt();
  int yes = 0;
  int no = 0;
  for (int q = 1; q <= t; q++) {
    setTestCase(q);
    int n = inf.readInt();
    int m = inf.readInt();
    vector<int> u(m);
    vector<int> v(m);
    for (int i = 0; i < m; i++) {
      u[i] = inf.readInt();
      v[i] = inf.readInt();
    }
    bool jury = readAns(ans, n, u, v);
    bool part = readAns(ouf, n, u, v);
    if (!jury && part) {
      quitf(_fail, "fail: participant found a solution but jury did not");
    }
    if (jury && !part) {
      quitf(_wa, "jury found a solution but participant did not");
    }
    yes += jury;
    no += !jury;
  }
  quitf(_ok, "ok, %d yes, %d no", yes, no);
}
