#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define LL long long
#define pb push_back
#define PB pop_back
#define PF pop_front
#define F first
#define S second
#define inrow(vec)    for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
#define incoloum(vec) for(int i=0;i<vec.size();i++)cout<<vec[i]<<endl;

const double PI=3.1415926;
const int KL=1e6;

using namespace std;

LL q,x,y,z,n,m,p[KL],mn=1e9,mx=-1e9,ans,k;
string t,s;
vector <LL> vec;
map <int,int> M;
 LL cnt1[30],cnt2[30];


int main()
{
    scl(q);
    while(q--){
        scl(n);scl(k);
        for(int i=0;i<26;i++){
            cnt1[i]=0;
            cnt2[i]=0;
        }
        cin>>t>>s;
        sort(all(s));sort(all(t));
        bool ok=true;
        for(int i=0;i<n;i++){
            if(t[i]>s[i]){
                ok=false;
                break;
            }
        }
        if(!ok){
            cout<<"No"<<endl;
            continue;
        }
       for(int i=0;i<n;i++){
          x=t[i]-'a';
          cnt1[x]++;
          x=s[i]-'a';
          cnt2[x]++;
       }
       for(int i=0;i<26;i++){
           if(cnt1[i]%k!=0){
              x=cnt1[i]%k;
              if(cnt2[i]<x){
                   ok=false;
                   break;
              }
              else {
                cnt2[i]-=x;
              }
           }
       }
       for(int i=0;i<26;i++){
          if(cnt2[i]%k!=0){
              ok=false;
              break;
          }
       }
       if(!ok){
        cout<<"No"<<endl;
       }
       else cout<<"Yes"<<endl;


    }
   return 0;
}
