#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using u64 = unsigned long long;
using u32 = unsigned int;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, long long>;
using pli = pair<long long, int>;
using pll = pair<long long, long long>;
template <typename T>
using uset = unordered_set<T>;
template <typename T1, typename T2>
using umap = unordered_map<T1, T2>;

template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#ifndef _DEBUG
#pragma GCC optimize("O3,unroll-loops,fast-math")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif

ll m;

pll f(ll x, char dx, ll y, char dy) {
    if (x == y)
        return {0, x};
    if (x > y) {
        swap(x, y);
        swap(dx, dy);
    }
    ll t = 0;
    if (dx == dy) {
        if (dx == 'L') {
            t += x - 1;
            y -= x - 1;
            x = 1;
            dx = 'R';
        } else {
            t += m - y;
            x += m - y;
            y = m;
            dy = 'L';
        }
    } else if (dx == 'L') {
        ll min_time = min(x - 1, m - y);
        x -= min_time;
        y += min_time;
        dx = 'R';
        if (y == m)
            dy = 'L';
        pll res = f(x, dx, y, dy);
        res.first += min_time;
        return res;
    }
    return {t + (y - x) / 2, (x + y) / 2};
}

pll intersect(pair<ll, char> x, pair<ll, char> y) {
    auto [t, p] = f(x.first, x.second, y.first, y.second);
    if (p < m + 1 - p) {
        p = m + 1 - p;
        t += m - 1;
    }
    return {t, p};
}

void normaliseSheep(pair<ll, char> &x) {
    if (x.first == 1)
        x.second = 'R';
    if (x.first == m)
        x.second = 'L';
}

pair<ll, char> moveSheep(pair<ll, char> x, ll t) {
    t %= 2 * (m - 1);
    if (t >= m - 1) {
        x.first = m + 1 - x.first;
        x.second = x.second == 'L' ? 'R' : 'L';
        normaliseSheep(x);
        t -= m - 1;
    }
    if (x.second == 'L') {
        if (t >= x.first - 1) {
            t -= x.first - 1;
            x = {1, 'R'};
            x.first += t;
        } else {
            x.first -= t;
        }
        normaliseSheep(x);
        return x;
    } else {
        if (t >= m - x.first) {
            t -= m - x.first;
            x = {m, 'L'};
            x.first -= t;
        } else {
            x.first += t;
        }
        normaliseSheep(x);
        return x;
    }
}

inline void solve() {
    int info;
    cin >> info;
    int n;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    string s;
    cin >> s;
    {
        set<ll> parities;
        for (int i = 0; i < n; i++)
            parities.insert(a[i] & 1);
        if (parities.size() == 2) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
    if (info == 1)
        return;
    vector<pair<ll, char>> sheep(n);
    for (int i = 0; i < n; i++) {
        sheep[i] = {a[i], s[i]};
        normaliseSheep(sheep[i]);
    }
    sort(all(sheep));
    sheep.resize(unique(all(sheep)) - sheep.begin());
    n = sheep.size();
    if (n == 1) {
        if (info >= 2)
            cout << m << '\n';
        if (info == 3)
            cout << 0 << '\n';
        return;
    }
    bool onlyR = true;
    for (int i = 0; i < n - 1; i++)
        if (sheep[i].second != 'R')
            onlyR = false;
    if (sheep[n - 1].first < m && sheep[n - 1].second == 'L')
        onlyR = false;
    if (onlyR) {
        ll T = 0;
        vector<pll> ops;
        T += m - sheep[n - 1].first;
        for (int i = 0; i < n; i++)
            sheep[i] = moveSheep(sheep[i], T);
        pair<ll, char> shL = sheep[n - 1];
        ll T1 = 0;
        for (int i = n - 2; i >= 0; i--) {
            sheep[i].first += T1;
            ll t = (shL.first - sheep[i].first) / 2;
            T1 += t;
            shL.first -= t;
            ops.push_back({T + T1, shL.first});
        }
        cout << shL.first << '\n';
        if (info == 3) {
            cout << ops.size() << '\n';
            for (auto [t, x] : ops)
                cout << t << ' ' << x << '\n';
        }
        return;
    }
    vector<pll> ops;
    ll T = 0;
    while (n > 1) {
        ll max_x = 0;
        ll opt_t = 0;
        for (int i = 0; i < n; i++)
            for (int j = i + 1; j < n; j++) {
                auto [t, x] = intersect(sheep[i], sheep[j]);
                if (max_x < x) {
                    max_x = x;
                    opt_t = t;
                }
            }
        for (int i = 0; i < n; i++)
            sheep[i] = moveSheep(sheep[i], opt_t);
        m = max_x;
        for (int i = 0; i < n; i++)
            normaliseSheep(sheep[i]);
        T += opt_t;
        ops.push_back({T, max_x});
        sort(all(sheep));
        sheep.resize(unique(all(sheep)) - sheep.begin());
        n = sheep.size();
    }
    if (info >= 2)
        cout << m << endl;
    if (info == 3) {
        cout << ops.size() << endl;
        for (auto [t, x] : ops)
            cout << t << ' ' << x << endl;
    }
}

signed main() {
#ifdef _DEBUG
    freopen("01.dat", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
#ifdef _DEBUG
    cin >> tt;
#endif
    for (int test_id = 1; test_id <= tt; test_id++) {
#ifdef _DEBUG
        cout << "Case #" << test_id << ":\n";
#endif
        solve();
    }
    return 0;
}
