//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
#define int long long
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")

signed main()
{
    int T;
    cin >> T;
    int n,m;
    cin >> n >> m;
    vector<int> e(n);
    for (int i=0;i<n;i++)
    {
        cin >> e[i];
        e[i]--;
    }
    string na;
    cin >> na;
    set<int> z;
    for (int i=0;i<n;i++)
    {
        if (e[i]==0)
        {
            z.insert(0);
        }
        else if (e[i]==m-1)
        {
            z.insert(m-1);
        }
        else if (na[i]=='R')
        {
            z.insert(e[i]);
        }
        else
        {
            z.insert(2*m-e[i]-2);
        }
    }
    vector<pair<int,int>> Q;
    int O=0;
    while (z.size()>1&&m>1)
    {
        string s(2*m-2,'0');
        for (auto i:z)
        {
            s[i] = '1';
        }
        //cout << s << "\n";
        s = s+s;
        n = s.size();
        int j=0;
        for (int i=0;i<n;i++)
        {
            if (s[i]=='1')
            {
                j = i;
                break;
            }
        }
        int ans=1e9,c=-1,cur=0,curc=0,f=-1;
        for (int i=j;i<n;i++)
        {
            if (s[i]=='0')
            {
                cur++;
                f = i;
            }
            else
            {
                if (cur%2)
                {
                    if (ans>cur)
                    {
                        ans = cur;
                        c = curc;
                    }
                }
                curc = i+1;
                cur = 0;
            }
        }
        //cout << ans << " " << c << "\n";
        if (f==-1)
        {
            cout << "No";
            return 0;
        }
        if (ans==1e9)
        {
            int t = ((m-f-1)%(2*m-2)+2*m-2)%(2*m-2);
            int x = m-1;
            set<int> z1;
            for (auto i:z)
            {
                int b = (i+t)%(2*m-2);
                if (b>m-1)
                {
                    b = 2*m-b-1;
                    z1.insert(2*x-b-1);
                }
                else
                {
                    z1.insert(b);
                }
            }
            swap(z,z1);
            m = x;
            O+=t;
            Q.push_back({O,x});
            continue;
        }
        int t = ((m-(c+ans/2)-1)%(2*m-2)+2*m-2)%(2*m-2);
        //cout << t << "\n";
        int x = m-ans/2-1;
        set<int> z1;
        for (auto i:z)
        {
            int b = (i+t)%(2*m-2);
            if (b>m-1)
            {
                b = 2*m-b-1;
                z1.insert(2*x-b-1);
            }
            else
            {
                z1.insert(b);
            }
        }
        swap(z,z1);
        m = x;
        O+=t;
        Q.push_back({O,x});
        break;
    }
    cout << "Yes\n";
    if (T>=2)
    {
        cout << m << "\n";
    }
    if (T>=3)
    {
        cout << Q.size() << "\n";
        for (auto [a,b]:Q)
        {
            cout << a << " " << b << "\n";
        }
    }
}

