#include <bits/stdc++.h>
#define ll long long 
#define all(v) v.begin(),v.end()
#define endl '\n'
#define PI acos(-1)
using namespace std;
void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll frea[27], freb[27];

int main()
{
    fast();
    int tt; cin >> tt;
    while (tt--)
    {
        memset(frea, 0, sizeof frea);
        memset(freb, 0, sizeof freb);
        bool p = true;
        ll n, k; cin >> n >> k;
        string a, b; cin >> a >> b;
        for (auto i : a)
            frea[i - 'a']++;
        for (auto i : b)
            freb[i - 'a']++;
        for (int i = 0; i < 26; i++)
       {
            ll m = min(frea[i], freb[i]);
            frea[i] -= m;
            freb[i] -= m;
        }
        for (int i = 0; i < 26; i++)
        {
            if (!(freb[i] % k)) {
                for (int j = 0; j < i; j++)
                {
                    if (frea[j] >= k)
                    {
                        ll m = min(freb[i], frea[j]);
                        frea[j] -= m;
                        freb[i] -= m;
                    }
                    if (!freb[i])
                        break;
                }
            }
            else {
                p = false;
                break;
            }
        }
       
        for(int i=0;i<26;i++)
            if (frea[i] != freb[i])
            {
                p = false;
                break;
            }
            
        if (p)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}