#include <bits/stdc++.h>

#define int long long
using ll = long long;
using ld = long double;
using namespace std;

const int INF = 1e18, MAXN = 1e5, mod = 998244353;

void solve();

int gg;

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int tt = 1;
    cin >> gg;
    // cin >> tt;
    while (tt--) {
        solve();
        cout << "\n";
    }
}

int mx_m = -INF;
vector<pair<int,int> > ans;

struct node {
    int m, t;
    string s;
    vector<int> arr;
    vector<pair<int,int> > ans1;
};

void solve() {
    int n, m;
    cin >> n >> m;
    m--;
    vector<int> arr(n);
    string s;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        arr[i]--;
    }
    cin >> s;


    bool check = true;
    for (int i = 1; i < n; i++) {
        if (arr[i] % 2 != arr[i - 1] % 2) {
            check = false;
        }
    }
    if (!check) {
        cout << "No";
        return;
    }
    cout << "Yes\n";

    map<node, int> mp;
    deque<node> q;
    q.push_back({m, 0, s, arr, {}});
    while (!q.empty()) {
        node pp = *q.begin();
        q.pop_front();
        node ppp = pp;
        if (mp[ppp] == 1) {
            continue;
        }
        bool check = true;
        int mx_r = -1;
        for (int i = 1; i < n; i++) {
            if (arr[i] != arr[i - 1] || s[i] != s[i - 1]) {
                check = false;
            }
            mx_r = max(mx_r, arr[i]);
        }
        if (check && pp.m < mx_m) {
            mx_m = pp.m;
            ans = pp.ans1;
        }
        for (int j = pp.m - 1; j > mx_r; j--) {
            node pp1 = pp;

            pp1.ans1.emplace_back(pp.t, j);
            pp1.m = j;
            for (int i = 0; i < n; i++) {
                if (pp1.arr[i] == 0 && pp1.s[i] == 'L') {
                    pp1.s[i] = 'R';
                }
                if (pp1.arr[i] == pp1.m && pp1.s[i] == 'R') {
                    pp1.s[i] = 'L';
                }
            }
            q.push_back(pp1);
        }

        node pp1 = pp;
        pp1.t++;
        for (int i = 0; i < n; i++) {
            if (pp1.s[i] == 'R') {
                pp1.arr[i]++;
            } else {
                pp1.arr[i]--;
            }
        }
        for (int i = 0; i < n; i++) {
            if (pp1.arr[i] == 0 && pp1.s[i] == 'L') {
                pp1.s[i] = 'R';
            }
            if (pp1.arr[i] == pp1.m && pp1.s[i] == 'R') {
                pp1.s[i] = 'L';
            }
        }

        q.push_back(pp1);
    }

    if (gg >= 2) {
        cout << ans.size() << "\n";
    }
    if (gg <= 3) {
        for (auto [t, m]: ans) {
            cout << t << ' ' << m << '\n';
        }
    }
}
