#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int nc, n, a, b, u, v;
int m; // number of future games that matter
int N; // number of nodes in my flow graph
int s, t; // source and sink
int adjMat[150][150];
int scoreSoFar[150];
bool seen[150];
const int INF = (1 << 20);


int getFlow(int currNode, int currCap) {
  if (currNode == t) return currCap;
  seen[currNode] = true;
  for(int i = 0; i < N; i++) if (!seen[i] && (adjMat[currNode][i] > 0)) {
    int amt = getFlow(i, min(currCap, adjMat[currNode][i]));
    if (amt > 0) {
      adjMat[currNode][i] -= amt;
      adjMat[i][currNode] += amt;
      return amt;
    }
  }
  return 0;
}

int main() {
  cin >> nc;
  while(nc--) {
    cin >> n >> a >> b;
    memset(adjMat, 0, sizeof(adjMat));
    memset(scoreSoFar, 0, sizeof(scoreSoFar));
    for(int i = 0; i < a; i++) {
      cin >> u >> v;
      scoreSoFar[u]++; // keep track of score so far
    }
    m = 0;
    for(int i = 0; i < b; i++) {
      cin >> u >> v;
      if (u == 0 || v == 0)
        scoreSoFar[0]++; // assume Ernie wins all other games he play
      else {
        // we got game m
        adjMat[u][m+n] = adjMat[v][m+n] = 1;
        m++;
      }
    }

    bool shouldTry = true;
    for(int i = 1; i < n && shouldTry; i++)
      if (scoreSoFar[i] > scoreSoFar[0]) { // there is no hope...
        cout << "NO" << endl;
        shouldTry = false;
      }
    if (!shouldTry) continue;
        

    // add a start and end node
    s = n+m;
    t = n+m+1;
    N = n+m+2;
    for(int i = 0; i < n; i++) // how much more they can win
      adjMat[s][i] = scoreSoFar[0] - scoreSoFar[i];
    for(int i = 0; i < m; i++) adjMat[n+i][t] = 1; // all games go down the sink :)

    int flow = 0;
    while(true) {
      memset(seen, 0, sizeof(seen));
      int augPath = getFlow(s, INF);
      if (augPath) flow += augPath;
      else break;
    }

    if (flow == m) cout << "YES" << endl;
    else           cout << "NO"  << endl;
  }
  return 0;
}
