#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; void solve(){ vector a(6), b(6); for (auto &&i : a) scanf("%d", &i); for (auto &&i : b) scanf("%d", &i); string s; cin >> s; int cur = 1; if(s == "TLE") cur = 2; if(s == "MLE") cur = 3; if(s == "OLE") cur = 4; if(s == "RE") cur = 5; for (int i = 1; i <= 5; ++i) { if(cur != i && b[i] != 0){ puts("No"); return; } if(cur == i && a[i] != 0){ puts("No"); return; } } puts("Yes"); } int main() { int t; cin >> t; while(t--){ solve(); } return 0; }