#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, w, t, m, o, r;
    cin >> a >> w >> t >> m >> o >> r;
    int b, x, u, n, p, s;
    cin >> b >> x >> u >> n >> p >> s;
    string c;
    cin >> c;
    bool flg = true;
    if (c == "WA") {
      if (w || u || n || p || s) flg = false;
    }
    if (c == "TLE") {
      if (x || t || n || p || s) flg = false;
    }
    if (c == "MLE") {
      if (x || u || m || p || s) flg = false;
    }
    if (c == "OLE") {
      if (x || u || n || o || s) flg = false;
    }
    if (c == "RE") {
      if (x || u || n || p || r) flg = false;
    }
    cout << (flg ? "Yes" : "No") << endl;
  }
  return 0;
}