/**
 *    author:  tourist
 *    created: 21.10.2026 15:02:44
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    dsu d(n);
    for (int i = 0; i < m; i++) {
      int l1, i1, l2, i2;
      cin >> l1 >> i1 >> l2 >> i2;
      d.unite(l1 - 1, l2 - 1);
    }
    bool ok = true;
    for (int i = 0; i < n; i++) {
      ok &= (d.get(i) == d.get(0));
    }
    cout << (ok ? "YES" : "NO") << '\n';
  }
  return 0;
}
