#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

#define uset unordered_set
#define umap unordered_map

#define ar array
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

#define FOR_B(i, a, b, x) for(int i=(a); (x)>0?i<(b):i>(b); i+=(x))
#define FOR_1(b) FOR_B(i, 0, b, 1)
#define FOR_2(i, b) FOR_B(i, 0, b, 1)
#define FOR_3(i, a, b) FOR_B(i, a, b, 1)
#define FOR_4(i, a, b, x) FOR_B(i, a, b, x)
#define FOR_Q(a, b, c, d, e, ...) e
#define FOR_G(...) FOR_Q(__VA_ARGS__, FOR_4, FOR_3, FOR_2, FOR_1)
#define FOR(...) FOR_G(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for(auto& x : a)

template<class T> string to_string(T v) {
	bool f=0;
	string res;
	EACH(x, v) {
		res+=(f?" ":"");
		f=1;
		res+=to_string(x);
	}
	return res;
}
string to_string(const char c) {
	return string(1, c);
}
string to_string(const bool b) {
	return b?"true":"false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(const string s) {
	return s;
}
string to_string(const vt<bool> v) {
	string res;
	FOR(sz(v))
		res+=(char)('0'+v[i]);
	return res;
}

template<class T> void read(T& x) {
	cin >> x;
}
template<class T> void read(vt<T>& a) {
	EACH(x, a)
		read(x);
}
template<class T, size_t S> void read(ar<T, S>& a) {
	EACH(x, a)
		read(x);
}
template<class T, class... O> void read(T& x, O&... o) {
	read(x);
	read(o...);
}

template<class T> void write(const T& x) {
	cout << to_string(x);
}
template<class T, class... O> void write(const T& x, const O&... o) {
	write(x);
	//if(sizeof...(o))
		//write(" ");
	write(o...);
}
void write() {
	write("\n");
}

template<class T, class U> void vti(vt<T>& v, U x, size_t n) {
	v=vt<T>(n, x);
}
template<class T, class U> void vti(vt<T>& v, U x, size_t n, size_t m...) {
	v=vt<T>(n);
	EACH(i, v)
		vti(i, x, m);
}



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	read(t);
	while(t--) {
		int n, k;
		string a, b;
		read(n, k, a, b);
		vt<int> da(26), db(26);
		FOR(n)
			++da[a[i]-'a'],
			++db[b[i]-'a'];
		bool ok=1;
		//write("da: ", da, "\n");
		//write("db: ", db, "\n");
		for(int i=0; i<26; ++i) {
			int l=da[i]/k;
			for(int j=i; j<26; ++j) {
				int l2=db[j]/k;
				int m=min(l, l2);
				da[i]-=m*k;
				db[j]-=m*k;
				l-=m;
			}
		}
		FOR(26) if(da[i]^db[i]) ok=0;
		//write("da: ", da, "\n");
		//write("db: ", db, "\n");
		write(ok?"YES":"NO");
		write();
	}
}
