#include <iostream>
#include <cstdio>
#include <cassert>
#include <vector>
#include <queue>
#include "testlib.h"
signed main(int argc, char *argv[]) {
    registerTestlibCmd(argc, argv);
    int id, T; id = inf.readInt(); T = inf.readInt();
    bool all_constructions_correct = true;
    std::string first_fail_msg = "";
    for (int t = 1; t <= T; t++) {
        int n, m; n = inf.readInt(); m = inf.readInt();
        std::vector<int> a(n), b(m);
        for (int i = 0; i < n; i++) a[i] = inf.readInt();
        for (int i = 0; i < m; i++) b[i] = inf.readInt();
        std::string jAns; jAns = ans.readToken();
        if (jAns == "Yes") {
            for (int i = 0, tmp; i < n - m; i++) tmp = ans.readInt();
        }
        std::string pAns; pAns = ouf.readToken();
        if (pAns != "Yes" && pAns != "No") {
            quitf(_wa, ("Test case #" + std::to_string(t) + ": Output must be 'Yes' or 'No', found " + pAns + ".").c_str());
        }
        if (pAns != jAns) {
            quitf(_wa, ("Test case #" + std::to_string(t) + ": Verdict mismatch. Expected " + jAns + ", found " + pAns + ".").c_str());
        }
        if (pAns == "No") {
            continue;
        }
        std::deque<int> dq(a.begin(), a.end());
        bool current_construction_ok = true;
        std::string current_fail_reason = "";
        for (int i = 0; i < n - m; i++) {
            int op; op = ouf.readInt();
            if (!current_construction_ok) continue;
            if (static_cast<int>(dq.size()) < 2) {
                // untouchable
                current_construction_ok = false;
                current_fail_reason = "Sequence length < 2 during operation";
                assert(false);
                continue;
            }
            if (op == 1) {
                int x = dq.front(); dq.pop_front();
                int y = dq.front(); dq.pop_front();
                dq.push_back(x ^ y);
            } else if (op == 2) {
                int x = dq.back(); dq.pop_back();
                int y = dq.back(); dq.pop_back();
                dq.push_front(x ^ y);
            } else {
                current_construction_ok = false;
                current_fail_reason = "Invalid operation type: " + std::to_string(op);
            }
        }
        // 验证最终序列
        if (current_construction_ok) {
            if (static_cast<int>(dq.size()) != m) {
                // untouchable
                assert(false);
            } else {
                for (int i = 0; i < m; i++) {
                    if (dq[i] != b[i]) {
                        current_construction_ok = false;
                        current_fail_reason = "Final sequence mismatch at index " + std::to_string(i);
                        break;
                    }
                }
            }
        }
        if (!current_construction_ok) {
            all_constructions_correct = false;
            if (first_fail_msg.empty()) {
                first_fail_msg = "Test case #" + std::to_string(t) + ": " + current_fail_reason + ".";
            }
        }
    }
    // 所有判定都正确的前提下 (否则上面已经 report(0) 了)
    if (all_constructions_correct) {
        quitf(_ok, "All cases passed with correct construction.");
    } else {
        // 判定全对，但构造有误，给 50% 分
        quitp(50, ("Correct verdicts, but construction failed. First error: " + first_fail_msg).c_str());
    }
    return 0;
}