Ashish has two strings $a$ and $b$, each of length $n$, and an integer $k$. The strings only contain lowercase English letters.

He wants to convert string $a$ into string $b$ by performing some (possibly zero) operations on $a$.

In one move, he can either

choose an index $i$ ($1 \leq i\leq n-1$) and swap $a_i$ and $a_{i+1}$, or

choose an index $i$ ($1 \leq i \leq n-k+1$) and if $a_i, a_{i+1}, \ldots, a_{i+k-1}$ are all equal to some character $c$ ($c \neq$ 'z'), replace each one with the next character $(c+1)$, that is, 'a' is replaced by 'b', 'b' is replaced by 'c' and so on.

Note that he can perform any number of operations, and the operations can only be performed on string $a$.

Help Ashish determine if it is possible to convert string $a$ into $b$ after performing some (possibly zero) operations on it.


-----Input-----

The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases. The description of each test case is as follows.

The first line of each test case contains two integers $n$ ($2 \leq n \leq 10^6$) and $k$ ($1 \leq k \leq n$).

The second line of each test case contains the string $a$ of length $n$ consisting of lowercase English letters.

The third line of each test case contains the string $b$ of length $n$ consisting of lowercase English letters.

It is guaranteed that the sum of values $n$ among all test cases does not exceed $10^6$.


-----Output-----

For each test case, print "Yes" if Ashish can convert $a$ into $b$ after some moves, else print "No".

You may print the letters of the answer in any case (upper or lower).


-----Examples-----

Input
4
3 3
abc
bcd
4 2
abba
azza
2 1
zz
aa
6 2
aaabba
ddddcc
Output
No
Yes
No
Yes


-----Note-----

In the first test case it can be shown that it is impossible to convert $a$ into $b$.

In the second test case,

"abba" $\xrightarrow{\text{inc}}$ "acca" $\xrightarrow{\text{inc}}$ $\ldots$ $\xrightarrow{\text{inc}}$ "azza".

Here "swap" denotes an operation of the first type, and "inc" denotes an operation of the second type.

In the fourth test case,

"aaabba" $\xrightarrow{\text{swap}}$ "aaabab" $\xrightarrow{\text{swap}}$ "aaaabb" $\xrightarrow{\text{inc}}$ $\ldots$ $\xrightarrow{\text{inc}}$ "ddaabb" $\xrightarrow{\text{inc}}$ $\ldots$ $\xrightarrow{\text{inc}}$ "ddddbb" $\xrightarrow{\text{inc}}$ $\ldots$ $\xrightarrow{\text{inc}}$ "ddddcc".

Difficulty: MEDIUM
Tags: String algorithms

Dynamic programming

Implementation

Greedy algorithms
Skill types: Dynamic programming

Greedy algorithms

Starter code:

Solutions:
import io, os
JJJ = input
input = lambda : JJJ().encode()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	S = [x - ord('a') for x in input().strip()]
	E = [x - ord('a') for x in input().strip()]
	s = [0 for x in range(26)]
	e = [0 for x in range(26)]
	for c in S:
		s[c] += 1
	for c in E:
		e[c] += 1
	for i in range(26):
		if i == 25 and s[i] != e[i]:
			print('No')
			break
		elif i == 25:
			continue
		diff = s[i] - e[i]
		if diff < 0 or diff % k != 0:
			print('No')
			break
		s[i] -= diff
		s[i + 1] += diff
	else:
		print('Yes')


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	d1 = [0] * 26
	d2 = [0] * 26
	for i in range(n):
		d1[ord(a[i]) - 97] += 1
		d2[ord(b[i]) - 97] += 1
	ans = 'Yes'
	j = 0
	for i in range(25):
		if d1[i] >= d2[i] and (not (d1[i] - d2[i]) % k):
			n -= d2[i]
			d1[i + 1] += d1[i] - d2[i]
		else:
			ans = 'No'
			break
		if not n:
			break
	print(ans)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def solve():
	for _ in range(get_int()):
		(n, k) = get_ints()
		a = get_string()
		b = get_string()
		(temp1, temp2) = ([0] * 26, [0] * 26)
		for i in a:
			temp1[ord(i) - 97] += 1
		for i in b:
			temp2[ord(i) - 97] += 1
		f = 0
		count = 0
		for i in range(26):
			d = temp1[i] - temp2[i]
			if d == 0:
				continue
			if abs(d) % k == 1:
				f = 1
				break
			count += d // k
			if count < 0:
				f = 1
				break
		if f:
			get_print('No')
		else:
			get_print('Yes')
solve()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	l1 = [0] * 26
	l2 = [0] * 26
	f = True
	for i in range(n):
		x = ord(a[i]) - ord('a')
		l1[x] += 1
	for i in range(n):
		x = ord(b[i]) - ord('a')
		l2[x] += 1
	for i in range(26):
		if l1[i] < l2[i] or (l1[i] - l2[i]) % k != 0:
			f = False
			break
		elif i < 25:
			l1[i + 1] += l1[i] - l2[i]
	if f:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
from collections import Counter

def convert(diff, k):
	(lena, lenb) = (0, 0)
	for letter in sorted(diff.keys()):
		n_letters = diff[letter]
		if n_letters > 0:
			lenb += n_letters
		else:
			lena += abs(n_letters)
		if lena < lenb:
			return 'NO'
	for (key, val) in diff.items():
		if abs(val) % k != 0:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = Counter(input()[:-1])
	b = Counter(input()[:-1])
	if a == b:
		print('YES')
		continue
	b.subtract(a)
	print(convert(b, k))


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	A = list(input().strip())
	B = list(input().strip())
	A = Counter([ord(a) - 97 for a in A])
	B = Counter([ord(b) - 97 for b in B])
	for i in range(26):
		if A[i] != B[i]:
			while A[i] > B[i] and A[i] >= k:
				A[i] -= k
				A[i + 1] += k
			if A[i] != B[i]:
				print('No')
				break
	else:
		print('Yes')


import sys
input = sys.stdin.readline
alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	d = dict()
	for i in alp:
		d[i] = 0
	for i in range(n):
		d[a[i]] += 1
	a = []
	for i in alp:
		a += [i] * d[i]
	d1 = dict()
	for i in alp:
		d1[i] = 0
	for i in range(n):
		d1[b[i]] += 1
	b = []
	for i in alp:
		b += [i] * d1[i]
	con = 0
	for i in range(n):
		if a[i] == b[i]:
			d[a[i]] -= 1
		elif a[i] > b[i]:
			con = 1
			break
		else:
			l = 0
			itr = i
			while alp[l] < b[i]:
				if d[alp[l]] > 0:
					if d[alp[l]] % k != 0:
						con = 1
						break
					else:
						while itr < n and a[itr] == alp[l]:
							d[a[itr]] -= 1
							a[itr] = b[i]
							d[b[i]] += 1
							itr += 1
				l += 1
			if con == 1:
				break
			else:
				d[a[i]] -= 1
	if con == 1:
		print('no')
	else:
		print('yes')


import sys, os
import math
from collections import Counter
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def MI():
	return map(int, input().split())

def out(var):
	sys.stdout.write(str(var) + '\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = Counter(input())
	b = Counter(input())
	broke = False
	for i in range(97, 123):
		c = chr(i)
		if a[c] != b[c]:
			if a[c] < b[c] or (a[c] - b[c]) % k != 0:
				broke = True
				break
			else:
				a[chr(i + 1)] += a[c] - b[c]
				a[c] = b[c]
	if not broke:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(input())
	b = list(input())
	(a_cnt, b_cnt) = ([0] * 27, [0] * 27)
	ans = 'YES'
	for i in range(n):
		a_cnt[ord(a[i]) - 97] += 1
		b_cnt[ord(b[i]) - 97] += 1
	for i in range(26):
		if a_cnt[i] < b_cnt[i] or (a_cnt[i] - b_cnt[i]) % k != 0:
			ans = 'NO'
			break
		a_cnt[i] -= b_cnt[i]
		a_cnt[i + 1] += a_cnt[i]
	print(ans)


import sys
import io, os
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = str(input())
	b = str(input())
	a = a[2:-3]
	b = b[2:-3]
	x = [0] * 27
	y = [0] * 27
	for c in a:
		i = ord(c) - ord('a')
		x[i] += 1
	for c in b:
		i = ord(c) - ord('a')
		y[i] += 1
	flag = True
	for i in range(26):
		if x[i] < y[i]:
			flag = False
			break
		x[i] -= y[i]
		if x[i] % k != 0:
			flag = False
			break
		x[i + 1] += x[i]
	if flag:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_string():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = get_ints()
	a = get_string()
	b = get_string()
	acount = [0] * 26
	bcount = [0] * 26
	for i in a:
		acount[ord(i) - ord('a')] += 1
	for i in b:
		bcount[ord(i) - ord('a')] += 1
	flag = True
	for i in range(25):
		extra = acount[i] - bcount[i]
		if extra < 0 or extra % k:
			flag = False
			break
		acount[i + 1] += extra
	if flag:
		print('Yes')
	else:
		print('No')


from sys import stdin
from collections import defaultdict
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = stdin.readline().strip()
	b = stdin.readline().strip()
	goal = defaultdict(int)
	for char in b:
		goal[char] += 1
	crnt = defaultdict(int)
	for char in a:
		crnt[char] += 1
	remain = defaultdict(int)
	optional = 0
	broke = False
	letters = set(goal.keys())
	letters = letters.union(set(crnt.keys()))
	letters = list(letters)
	for key in sorted(letters):
		if crnt[key] - goal[key] > 0 and (crnt[key] - goal[key]) % k == 0 and (key != 'z'):
			optional += (crnt[key] - goal[key]) // k
		elif (goal[key] - crnt[key]) % k == 0 and optional >= (goal[key] - crnt[key]) // k:
			optional -= (goal[key] - crnt[key]) // k
		elif crnt[key] == goal[key]:
			continue
		else:
			broke = True
			break
	if broke:
		print('No')
	else:
		print('Yes')


import sys
from math import ceil, factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(int(input())):
	(n, k) = rl()
	(a, b) = (sys.stdin.readline(), sys.stdin.readline())
	(c1, c2) = ([0] * 26, [0] * 26)
	for i in range(n):
		c1[ord(a[i]) - ord('a')] += 1
		c2[ord(b[i]) - ord('a')] += 1
	flag = True
	for i in range(25):
		x = c1[i] - c2[i]
		if x < 0 or x % k:
			flag = False
			break
		c1[i] = c2[i]
		c1[i + 1] += x
	print('YES') if flag else print('NO')


import sys
rd = sys.stdin.readline
from collections import Counter
t = int(rd())
for _ in range(t):
	(n, k) = map(int, rd().split())
	a = list(rd())
	b = list(rd())
	ca = Counter(a)
	cb = Counter(b)
	ok = True
	amari = 0
	for i in range(97, 122):
		x = ca[chr(i)] - cb[chr(i)]
		if x < 0 or x % k != 0:
			ok = False
			break
		ca[chr(i + 1)] += x
	if ok:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	l1 = [0] * 26
	l2 = [0] * 26
	for i in range(n):
		l1[ord(a[i]) - 97] += 1
		l2[ord(b[i]) - 97] += 1
	f = False
	for i in range(25):
		z = l1[i] - l2[i]
		if z < 0 or z % k:
			f = True
			break
		l1[i] = l2[i]
		l1[i + 1] += z
	print(['No', 'Yes'][l1 == l2])


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	c = [0] * 26
	for i in input():
		c[ord(i) - 97] += 1
	for i in input():
		c[ord(i) - 97] -= 1
	c = [i for i in c if i != 0]
	a = 0
	for i in c:
		if abs(i) % k == 0 and a >= 0:
			a += i
		else:
			print('No')
			break
	else:
		print('Yes')


import math
import sys
inf = float('inf')
mod = 10 ** 9 + 7
input = sys.stdin.readline
from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	c1 = Counter(a)
	c2 = Counter(b)
	ans = 'Yes'
	for i in range(26):
		if c2[chr(i + 97)] > c1[chr(i + 97)] or (c1[chr(i + 97)] - c2[chr(i + 97)]) % k != 0:
			ans = 'No'
			break
		c1[chr(i + 98)] += c1[chr(i + 97)] - c2[chr(i + 97)]
	print(ans)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [i for i in input().strip()]
	b = [i for i in input().strip()]
	a.sort()
	b.sort()
	if a > b:
		print('NO')
	else:
		ok = True
		count_a = [0] * 26
		count_b = [0] * 26
		for i in a:
			count_a[ord(i) - 97] += 1
		for i in b:
			count_b[ord(i) - 97] += 1
		for i in range(26):
			if count_a[i] < count_b[i] or count_a[i] % k != count_b[i] % k:
				ok = False
				break
			if i != 25:
				count_a[i + 1] += count_a[i] - count_b[i]
			elif count_a[i] > count_b[i]:
				ok = False
				break
		print('YES' if ok else 'NO')


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	for _ in range(int(input())):
		(n, k) = inar()
		arr = list(input())
		br = list(input())
		d1 = defaultdict(int)
		d2 = defaultdict(int)
		for i in arr:
			d1[i] += 1
		for i in br:
			d2[i] += 1
		take = []
		now = []
		check = True
		for i in d2.keys():
			if i in d1:
				temp = d1[i] - d2[i]
				if temp < 0:
					now.append((i, abs(temp)))
				elif temp > 0:
					take.append((i, temp))
			else:
				now.append((i, d2[i]))
		for i in d1.keys():
			if i not in d2:
				take.append((i, d1[i]))
		take.sort()
		now.sort()
		for (i, j) in take:
			if i == 'z':
				check = False
				break
		if not check:
			print('NO')
			continue
		for (j, i) in take:
			if i % k != 0:
				check = False
				break
		if check:
			for (j, i) in now:
				if i % k != 0:
					check = False
					break
		fr = []
		for (i, j) in take:
			fr.append((i, j, 1))
		for (i, j) in now:
			fr.append((i, j, 2))
		fr.sort()
		count = 0
		lol = False
		for (p, i, j) in fr:
			if j == 1:
				if not lol:
					lol = True
				count += i
			else:
				count -= i
			if count < 0:
				check = False
				break
			if count == 0 and lol == False:
				check = False
				break
		if check:
			print('YES')
		else:
			print('NO')
main()


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def cal(s):
	res = [0] * 26
	for c in s:
		res[c - 97] += 1
	return res
for _ in range(II()):
	(n, k) = MI()
	a = BI()
	b = BI()
	li1 = cal(a)
	li2 = cal(b)
	c = 0
	f = 0
	for (x, y) in zip(li1, li2):
		d = x - y
		if d == 0:
			continue
		if abs(d) % k:
			f = 1
			break
		c += d // k
		if c < 0:
			f = 1
			break
	if f:
		print('NO')
	else:
		print('YES')


import sys
from sys import stdin
t = int(stdin.readline())
alp = 'abcdefghijklmnopqrstuvwxyz'
ad = {}
for i in range(26):
	ad[alp[i]] = i
for i in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = stdin.readline()[:-1]
	b = stdin.readline()[:-1]
	have = [0] * 27
	must = [0] * 27
	for c in a:
		have[ad[c]] += 1
	for c in b:
		must[ad[c]] += 1
	flag = False
	nowa = 0
	nowb = 0
	for i in range(26):
		nowa += have[i]
		nowb = must[i]
		if nowb > nowa:
			flag = True
			break
		nowa -= nowb
		if nowa % k != 0:
			flag = True
			break
	if flag:
		print('No')
	else:
		print('Yes')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	s1 = input()
	s2 = input()
	(h1, h2) = ([0] * 26, [0] * 26)
	for i in range(n):
		h1[ord(s1[i]) - ord('a')] += 1
		h2[ord(s2[i]) - ord('a')] += 1
	f = True
	for i in range(26):
		if i == 25 and h1[i] != h2[i]:
			f = False
			break
		if (h1[i] - h2[i]) % k or h2[i] > h1[i]:
			f = False
			break
		if i != 25:
			h1[i + 1] += h1[i] - h2[i]
	if f == False:
		print('No')
	else:
		print('Yes')


from collections import defaultdict
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s1 = input()
	s2 = input()
	l = [0] * 26
	ll = [0] * 26
	for i in range(a):
		l[ord(s1[i]) - 97] += 1
		ll[ord(s2[i]) - 97] += 1
	flag = 0
	for i in range(25):
		if l[i] < ll[i]:
			flag = 1
		else:
			k = l[i] - ll[i]
			if k % b != 0:
				flag = 1
			else:
				l[i + 1] += k
	if flag:
		print('No')
	else:
		print('Yes')


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		(n, k) = mi()
		f1 = [0] * 27
		f2 = f1[:]
		a = si()
		b = si()
		for i in a:
			f1[bo(i)] += 1
		for i in b:
			f2[bo(i)] += 1
		f = 0
		for i in range(26):
			mnx = min(f1[i], f2[i])
			f1[i] -= mnx
			f2[i] -= mnx
			if f1[i] % k or f2[i] % k:
				f = 1
				break
		if f:
			print('NO')
			continue
		for i in range(26):
			if f1[i] >= f2[i]:
				f1[i] -= f2[i]
				f2[i] = 0
			f1[i + 1] += f1[i]
			f1[i] = 0
		for i in range(26):
			if f2[i]:
				f = 1
				break
		print('NO' if f else 'YES')
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	c1 = [0] * 26
	c2 = [0] * 26
	for i in range(0, n):
		c1[ord(a[i]) - 97] += 1
		c2[ord(b[i]) - 97] += 1
	ans = 'YES'
	for j in range(0, 26):
		if c1[j] == c2[j]:
			continue
		elif c2[j] > c1[j]:
			ans = 'NO'
			break
		elif (c1[j] - c2[j]) % k != 0:
			ans = 'NO'
			break
		else:
			c1[j + 1] += c1[j] - c2[j]
	print(ans)


import sys
from string import ascii_lowercase
input = sys.stdin.readline

def possible(hashA, hashB, k):
	for letter in hashA:
		if hashA[letter] == hashB[letter]:
			pass
		elif hashA[letter] < hashB[letter]:
			return False
		elif (hashA[letter] - hashB[letter]) % k != 0:
			return False
		else:
			nextLetter = chr(ord(letter) + 1)
			hashA[nextLetter] += hashA[letter] - hashB[letter]
	return True
tests = int(input())
for test in range(tests):
	(strLen, k) = map(int, input().split())
	stringA = input()
	stringB = input()
	hashA = {}
	hashB = {}
	for letter in ascii_lowercase:
		hashA[letter] = 0
		hashB[letter] = 0
	for a in stringA.rstrip():
		hashA[a] += 1
	for b in stringB.rstrip():
		hashB[b] += 1
	if possible(hashA, hashB, k):
		print('YES')
	else:
		print('NO')


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, OrderedDict, deque
from string import ascii_lowercase, ascii_uppercase
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
inp = sys.stdin.readline
for _ in range(int(inp())):
	(n, k) = map(int, inp().split())
	a = inp()
	b = inp()
	(d1, d2) = (defaultdict(int), defaultdict(int))
	for i in a:
		d1[i] += 1
	for i in b:
		d2[i] += 1
	f = 'Yes'
	a = ascii_lowercase
	for i in range(25):
		if d2[a[i]] > d1[a[i]] or (d2[a[i]] - d1[a[i]]) % k:
			f = 'No'
			break
		d1[a[i + 1]] += d1[a[i]] - d2[a[i]]
	print(f)
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [0] * 26
	for x in input():
		a[ord(x) - 97] += 1
	for x in input():
		a[ord(x) - 97] -= 1
	a = [x for x in a if x != 0]
	t = 0
	pas = True
	for x in a:
		if abs(x) % k == 0 and t > -1:
			t += x
		else:
			pas = False
			break
	print('Yes' if pas else 'No')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(s, t) = (input(), input())
	c = [0] * 26
	for i in range(n):
		c[ord(s[i]) - 97] += 1
		c[ord(t[i]) - 97] -= 1
	for j in range(25):
		d = c[j]
		if d < 0 or d % k:
			break
		c[j] -= d
		c[j + 1] += d
	print(['No', 'Yes'][all((i == 0 for i in c))])


import os
import sys
from io import BytesIO, IOBase

def main():
	test_cases = int(input())
	while test_cases:
		(n, k) = list(map(int, input().split()))
		string1 = input()
		string2 = input()
		have = [0] * 27
		need = [0] * 27
		for ch in string1:
			have[ord(ch) - ord('a')] += 1
		for ch in string2:
			need[ord(ch) - ord('a')] += 1
		ans = 'YES'
		for i in range(25, -1, -1):
			have[i] += have[i + 1]
			need[i] += need[i + 1]
			if have[i] > need[i] or (need[i] - have[i]) % k != 0:
				ans = 'NO'
				break
		print(ans)
		test_cases -= 1
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	if y == 0:
		return 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(val, pair):
	summ = 0
	for x in pair:
		if x[1] > val:
			summ += x[0]
	return summ > val

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	(n, k) = read()
	a = list(string())
	b = list(string())
	freqa = [0] * 26
	freqb = [0] * 26
	for c in a:
		freqa[ord(c) - 97] += 1
	for c in b:
		freqb[ord(c) - 97] += 1
	rem = 0
	for (x, y) in zip(freqa, freqb):
		d = x - y
		if d == 0:
			continue
		if abs(d) % k:
			print('NO')
			break
		rem += d // k
		if rem < 0:
			print('NO')
			break
	else:
		print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = scanner()
for i in range(t):
	solve()


def fun(A, B, n, k):
	temp = [0] * 26
	t = ord('a')
	for i in range(n):
		temp[ord(A[i]) - t] -= 1
		temp[ord(B[i]) - t] += 1
	cu = 0
	for i in range(26):
		if temp[i] == 0:
			continue
		else:
			if abs(temp[i]) % k != 0:
				print('NO')
				return
			if temp[i] > 0:
				if cu < temp[i]:
					print('NO')
					return
				else:
					cu -= temp[i]
			else:
				cu += abs(temp[i])
	print('YES')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	fun(a, b, n, k)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	ca = [0 for i in range(26)]
	cb = [0 for i in range(26)]
	for i in range(n):
		ca[ord(a[i]) - 97] += 1
		cb[ord(b[i]) - 97] += 1
	c = 0
	ok = True
	for i in range(26):
		x = ca[i] - cb[i]
		if x % k:
			ok = False
			break
		c += x
		if c < 0:
			ok = False
			break
	if ok:
		print('yes')
	else:
		print('no')


import sys

def input():
	return sys.stdin.readline()[:-1]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = [0] * 26
	B = [0] * 26
	for a in input():
		A[ord(a) - 97] += 1
	for b in input():
		B[ord(b) - 97] += 1
	ans = 'Yes'
	for i in range(25):
		if A[i] >= B[i] and (A[i] - B[i]) % k == 0:
			A[i + 1] += A[i] - B[i]
		else:
			ans = 'No'
			break
	print(ans)


import sys, string
input = sys.stdin.readline
from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(a, b) = (input()[:-1], input()[:-1])
	cnta = Counter(a)
	cntb = Counter(b)
	for i in string.ascii_lowercase:
		if cnta[i] < cntb[i] or (cntb[i] - cnta[i]) % k:
			print('No')
			break
		cnta[chr(ord(i) + 1)] += cnta[i] - cntb[i]
	else:
		print('Yes')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s1 = list(input().strip())
	s2 = list(input().strip())
	(c1, c2) = ([0] * 26, [0] * 26)
	for i in range(a):
		c1[ord(s1[i]) - 97] += 1
		c2[ord(s2[i]) - 97] += 1
	ans = 'Yes'
	for j in range(25):
		if c1[j] < c2[j]:
			ans = 'No'
			break
		else:
			k = c1[j] - c2[j]
			if k % b:
				ans = 'No'
				break
			c1[j] = c2[j]
			c1[j + 1] += k
	print(['No', 'Yes'][c1 == c2])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	alist = [0] * 26
	blist = [0] * 26
	for i in range(n):
		alist[ord(a[i]) - 97] += 1
		blist[ord(b[i]) - 97] += 1
	flag = True
	for i in range(26):
		if alist[i] < blist[i] or (alist[i] - blist[i]) % k:
			flag = False
		alist[i] -= blist[i]
		alist[min(i + 1, 25)] += alist[i]
	print('YES' if flag else 'NO')


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n
for xyz in range(0, int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	t = list(input())
	for i in range(0, n):
		s[i] = ord(s[i]) - 97
		t[i] = ord(t[i]) - 97
	cnts = [0] * 26
	cntt = [0] * 26
	for i in range(0, n):
		cnts[s[i]] += 1
		cntt[t[i]] += 1
	for i in range(0, 26):
		if cnts[i] >= cntt[i]:
			cnts[i] -= cntt[i]
			cntt[i] = 0
		else:
			cntt[i] -= cnts[i]
			cnts[i] = 0
	s = [0] * sum(cnts)
	t = [0] * sum(cntt)
	i = 0
	ps = pt = 0
	while i < 26:
		for j in range(ps, ps + cnts[i]):
			s[j] = i
		ps += cnts[i]
		for j in range(pt, pt + cntt[i]):
			t[j] = i
		pt += cntt[i]
		i += 1
	i = 0
	f = True
	n = len(s)
	while i < n:
		if s[i] > t[i]:
			f = False
			break
		if s[i] < t[i]:
			if i + k <= n:
				temp = s[i]
				temp2 = t[i]
				for j in range(i, i + k):
					if s[j] != temp or t[j] != temp2:
						f = False
						break
				if f:
					i += k
				else:
					break
			else:
				f = False
				break
		else:
			i += 1
	if f:
		print('Yes')
	else:
		print('No')


import sys

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def BI():
	return sys.stdin.buffer.readline().rstrip()

def cal(s):
	res = [0] * 26
	for c in s:
		res[c - 97] += 1
	return res
for _ in range(II()):
	(n, k) = MI()
	a = BI()
	b = BI()
	li1 = cal(a)
	li2 = cal(b)
	c = 0
	f = 0
	for (x, y) in zip(li1, li2):
		d = x - y
		if d == 0:
			continue
		if abs(d) % k:
			f = 1
			break
		c += d // k
		if c < 0:
			f = 1
			break
	if f:
		print('NO')
	else:
		print('YES')


import sys, threading
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
mp = lambda : map(int, input().split())
ml = lambda : list(mp())
get_float = lambda : map(float, input().split())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def solve():

	def geti(x):
		return ord(x) - ord('a')
	(n, k) = ml()
	s1 = input()
	s2 = input()
	dct1 = [0] * 26
	dct2 = [0] * 26
	for i in range(n):
		dct1[geti(s1[i])] += 1
		dct2[geti(s2[i])] += 1
	test = 0
	extra = 0
	for i in range(26):
		if dct2[i]:
			take = min(dct2[i], dct1[i])
			dct2[i] -= take
			dct1[i] -= take
			if dct2[i]:
				if dct2[i] % k != 0:
					test = 1
					break
				need = dct2[i] // k
				if extra < need:
					test = 1
					break
				extra -= need
		extra += dct1[i] // k
	if test:
		print('No')
	else:
		print('Yes')
t = scanner()
for i in range(t):
	solve()


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, k) = [int(x) for x in stdin.readline().split()]
	a = stdin.readline().strip()
	b = stdin.readline().strip()
	a = [ord(char) for char in sorted(a, reverse=True)]
	b = [ord(char) for char in sorted(b, reverse=True)]
	answer = -1
	while answer == -1:
		if len(a) == 0:
			answer = 'Yes'
		elif a[-1] > b[-1]:
			answer = 'No'
		elif a[-1] == b[-1]:
			a.pop()
			b.pop()
		else:
			pointer = 0
			while pointer < len(a) and a[-1 - pointer] == a[-1]:
				pointer += 1
			if pointer % k != 0:
				answer = 'No'
			else:
				for i in range(pointer):
					a[-1 - i] += 1
	stdout.write(answer + '\n')


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for k in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	(N, K) = MAP()
	S = [ord(s) - 97 for s in input()]
	T = [ord(s) - 97 for s in input()]
	C1 = [0] * 26
	C2 = [0] * 26
	for i in range(N):
		C1[S[i]] += 1
		C2[T[i]] += 1
	ok = 1
	for c in range(26):
		if C1[c] < C2[c]:
			ok = 0
			break
		while C1[c] > C2[c]:
			C1[c] -= K
			C1[c + 1] += K
		if C1[c] != C2[c]:
			ok = 0
			break
	if ok:
		Yes()
	else:
		No()


import sys

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def llinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math as m
for _ in range(iinp()):
	(n, k) = ninp()
	a = sinp()
	b = sinp()
	first = [0] * 26
	second = [0] * 26
	for c in b:
		second[ord(c) - 97] += 1
	for c in a:
		first[ord(c) - 97] += 1
	f = 0
	for i in range(26):
		s1 = first[i]
		s2 = second[i]
		if s2 > s1:
			print('No')
			f = 1
			break
		elif s1 == s2:
			pass
		else:
			diff = s1 - s2
			if diff % k == 0:
				first[i] = first[i] - diff
				first[i + 1] += diff
			else:
				print('No')
				f = 1
				break
	if f == 0:
		p('Yes')


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		strings = [input().strip(), input().strip()]
		amts = [[0] * 26 for i in range(2)]
		total = 0
		total2 = 0
		worked = True
		for i in range(2):
			for j in range(n):
				amts[i][ord(strings[i][j]) - ord('a')] += 1
		for j in range(26):
			total += amts[0][j]
			total2 += amts[1][j]
			if total < total2 or (amts[1][j] - amts[0][j]) % k != 0:
				worked = False
		print('Yes' if worked else 'No')
prog()


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	ac = [0] * 26
	bc = [0] * 26
	for i in range(n):
		ac[ord(a[i]) - 97] += 1
		bc[ord(b[i]) - 97] += 1
	for i in range(26):
		if ac[i] >= bc[i]:
			ac[i] -= bc[i]
			if i + 1 < 26:
				m = ac[i] // k
				ac[i] -= m * k
				ac[i + 1] += m * k
		else:
			return 'NO'
	return 'YES'
t = int(input())
i = 0
while i < t:
	print(solve())
	i += 1


import os
import sys
from io import BytesIO, IOBase
from math import sqrt
from collections import Counter

def fn(x):
	return 10 * sqrt(x) + x
lim = 2 * 10 ** 18 + 1

def main():
	(n, k1) = map(int, input().split())
	a = Counter(input())
	b = Counter(input())
	d = a.copy()
	req = b.copy()
	for (k, v) in b.items():
		if k in d:
			if v > d[k]:
				req[k] -= d[k]
				d[k] = 0
			else:
				d[k] -= v
				req[k] = 0
	aa = []
	for (k, v) in d.items():
		aa += [k] * v
	bb = []
	for (k, v) in req.items():
		bb += [k] * v
	aa.sort()
	bb.sort()
	f = 1
	nn = len(aa)
	for i in range(0, nn, k1):
		f = 1
		upar = aa[i]
		nee = bb[i]
		j = i
		c = 0
		while c < k1 and j < nn:
			if aa[j] == upar and nee == bb[j] and (aa[j] <= bb[j]):
				c += 1
				j += 1
				continue
			else:
				f = 0
				break
			c += 1
			j += 1
		if c != k1 or f == 0:
			f = 0
			break
	print('Yes' if f else 'No')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	d1 = [0] * 26
	d2 = [0] * 26
	for (i1, i2) in zip(a, b):
		d1[ord(i1) - 97] += 1
		d2[ord(i2) - 97] += 1
	ans = 'YES'
	for (i, v) in enumerate(d1):
		if d1[i] != d2[i]:
			if v < d2[i] or (v - d2[i]) % k or i == 25:
				ans = 'NO'
				break
			else:
				d1[i] = d2[i]
				d1[i + 1] += v - d2[i]
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = input()
	b = input()
	one = [0] * 26
	two = [0] * 26
	for j in range(n):
		one[ord(a[j]) - ord('a')] += 1
		two[ord(b[j]) - ord('a')] += 1
	verdict = 'Yes'
	for j in range(26):
		diff = one[j] - two[j]
		if diff < 0 or diff % k > 0:
			verdict = 'No'
			break
		elif j == 25 and diff > 0:
			verdict = 'No'
			break
		if j < 25:
			one[j + 1] += diff
	print(verdict)


from sys import stdout, stdin, maxsize
from collections import defaultdict, deque
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	s = stdin.readline().strip()
	ss = stdin.readline().strip()
	a = [0] * 26
	b = [0] * 26
	for i in s:
		a[ord(i) - 97] += 1
	for i in ss:
		b[ord(i) - 97] += 1
	c = [0] * 26
	for i in range(26):
		c[i] = a[i] - b[i]
	ans = 'Yes'
	for i in range(26):
		if c[i] % k != 0:
			ans = 'No'
			break
	if a[25] > b[25]:
		ans = 'No'
	if b[0] > a[0]:
		ans = 'No'
	temp = 0
	te = 0
	for i in range(26):
		temp += a[i]
		te += b[i]
		if temp < te:
			ans = 'No'
			break
	stdout.write(ans + '\n')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input().rstrip()
	b = input().rstrip()
	data_a = [0 for i in range(26)]
	data_b = [0 for i in range(26)]
	for i in range(n):
		data_a[ord(a[i]) - 97] += 1
		data_b[ord(b[i]) - 97] += 1
	for i in range(25):
		if data_a[i] >= data_b[i]:
			if (data_a[i] - data_b[i]) % k:
				print('No')
				break
			data_a[i + 1] += data_a[i] - data_b[i]
		else:
			print('No')
			break
	else:
		print('Yes')


import os
from heapq import heapify, heappop, heappush
import sys
import sys, threading
import math
import operator
import bisect
from collections import defaultdict
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, k) = inpt()
		ar = list(input())
		br = list(input())
		d1 = defaultdict(int)
		d2 = defaultdict(int)
		for i in ar:
			d1[i] += 1
		for i in br:
			d2[i] += 1
		extra = []
		less = []
		ok = True
		for i in d2.keys():
			if i in d1:
				temp = d1[i] - d2[i]
				if temp < 0:
					less.append((i, abs(temp)))
				elif temp > 0:
					extra.append((i, temp))
			else:
				less.append((i, d2[i]))
		for i in d1.keys():
			if i not in d2:
				extra.append((i, d1[i]))
		extra.sort()
		less.sort()
		for (i, j) in extra:
			if i == 'z':
				ok = False
				break
		if not ok:
			print('NO')
			continue
		for (j, i) in extra:
			if i % k != 0:
				ok = False
				break
		if ok:
			for (j, i) in less:
				if i % k != 0:
					ok = False
					break
		fr = []
		for (i, j) in extra:
			fr.append((i, j, 1))
		for (i, j) in less:
			fr.append((i, j, 2))
		fr.sort()
		count = 0
		st = False
		for (p, i, j) in fr:
			if j == 1:
				if not st:
					st = True
				count += i
			else:
				count -= i
			if count < 0:
				ok = False
				break
			if count == 0 and st == False:
				ok = False
				break
		if ok:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import defaultdict
from sys import stdin

def input():
	return stdin.buffer.readline()
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	str0 = input()
	str1 = input()
	cnt0 = defaultdict(lambda : 0)
	cnt1 = defaultdict(lambda : 0)
	for s in str0:
		cnt0[s] += 1
	for s in str1:
		cnt1[s] += 1
	i = 0
	j = 0
	for i in range(97, 122):
		d = cnt0[i] - cnt1[i]
		if d < 0 or d % k != 0:
			print('No')
			break
		else:
			cnt0[i + 1] += d
	else:
		print('Yes')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = str(input())
	b = str(input())
	l1 = [0] * 27
	l2 = [0] * 27
	for i in range(n):
		l1[int(ord(a[i]) - ord('a'))] += 1
		l2[int(ord(b[i]) - ord('a'))] += 1
	f = 0
	d = 0
	for i in range(26):
		temp = l1[i] - l2[i]
		if temp < 0:
			f = 1
			break
		if temp % k != 0:
			f = 1
			break
		l1[i + 1] += temp
	if f == 0:
		print('Yes')
	else:
		print('No')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from collections import defaultdict as dc
alpha = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(N()):
	(n, k) = RL()
	(a, b) = (input().strip(), input().strip())
	(dic, s) = (dc(int), dc(int))
	for c in a:
		dic[c] += 1
	for c in b:
		s[c] += 1
	flag = True
	p = 0
	for i in range(26):
		c = alpha[i]
		if dic[c] < s[c] % k:
			flag = False
			break
		dic[c] -= s[c] % k
		p += dic[c] // k
		if p < s[c] // k:
			flag = False
			break
		p -= s[c] // k
	print('Yes' if flag else 'No')


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]

def main():
	N0 = int(input())
	for _ in range(N0):
		(N, K) = map(int, input().split())
		A = sorted(list(input()))
		B = sorted(list(input()))
		C1 = collections.Counter(A)
		C2 = collections.Counter(B)
		L1 = []
		L2 = []
		for i in range(26):
			c = chr(ord('a') + i)
			n1 = 0
			if c in C1:
				n1 = C1[c]
			n2 = 0
			if c in C2:
				n2 = C2[c]
			a = min(n1, n2)
			n1 -= a
			n2 -= a
			L1.append(n1)
			L2.append(n2)
		result = True
		for i in range(26):
			if L1[i] % K != 0 or L2[i] % K != 0:
				result = False
				break
			while L1[i] > 0:
				for j in range(i, 26):
					if L2[j] > 0:
						L1[i] -= K
						L2[j] -= K
						break
				else:
					result = False
					break
		if result:
			print('Yes')
		else:
			print('No')
main()


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	f1 = [0 for i in range(26)]
	f2 = [0 for i in range(26)]
	a = input()
	b = input()
	for i in range(n):
		f1[ord(a[i]) - 97] += 1
		f2[ord(b[i]) - 97] += 1
	poss = 1
	curr = 0
	for i in range(26):
		curr += f1[i]
		if curr < f2[i]:
			poss = 0
			break
		curr -= f2[i]
		curr = curr - curr % k
	if poss:
		print('Yes')
	else:
		print('No')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	alist = [0] * 26
	blist = [0] * 26
	for i in range(n):
		alist[ord(a[i]) - 97] += 1
		blist[ord(b[i]) - 97] += 1
	flag = 0
	tmp = 0
	for i in range(26):
		if (blist[i] - alist[i]) % k != 0:
			flag = 1
			break
		tmp += alist[i] - blist[i]
		if tmp < 0:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


import random, math, sys, os, heapq
from bisect import bisect_left, bisect_right
from collections import Counter
from io import BytesIO, IOBase
input = sys.stdin.readline

def solution(a, b, n, k):
	ma = Counter(list(a))
	mb = Counter(list(b))
	li = list(mb.keys())
	for i in li:
		if i in ma:
			mini = min(ma[i], mb[i])
			ma[i] -= mini
			mb[i] -= mini
			if ma[i] == 0:
				del ma[i]
			if mb[i] == 0:
				del mb[i]
	for i in range(ord('a'), ord('z')):
		if chr(i) in ma and ma[chr(i)] >= k:
			for j in range(i + 1, ord('z') + 1):
				if chr(j) in mb and mb[chr(j)] >= k:
					multa = ma[chr(i)] // k
					multb = mb[chr(j)] // k
					mini = min(multa, multb)
					ma[chr(i)] -= k * mini
					mb[chr(j)] -= k * mini
	for i in range(ord('a'), ord('z')):
		if chr(i) in ma and ma[chr(i)] == 0:
			del ma[chr(i)]
	if len(ma) == 0:
		return 'YES'
	return 'NO'

def input_test():
	for _ in range(int(input())):
		(n, k) = map(int, input().strip().split(' '))
		a = input().strip()
		b = input().strip()
		print(solution(a, b, n, k))

def test():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
input_test()


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = str(input())
	b = str(input())
	ac = [0 for i in range(26)]
	bc = [0 for i in range(26)]
	for i in range(n):
		ac[ord(a[i]) - ord('a')] += 1
		bc[ord(b[i]) - ord('a')] += 1
	x = 0
	for i in range(26):
		if bc[i] > ac[i] + x:
			print('NO')
			break
		if x % k != 0:
			print('NO')
			break
		x = ac[i] + x - bc[i]
	else:
		print('YES')


from sys import *
from math import *
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = stdin.readline()
	b = stdin.readline()
	c1 = [0] * 26
	c2 = [0] * 26
	for i in range(n):
		c1[ord(a[i]) - ord('a')] += 1
		c2[ord(b[i]) - ord('a')] += 1
	f = True
	for i in range(26):
		if i == 25:
			if c1[i] != c2[i]:
				f = False
				break
		if (c1[i] - c2[i]) % k or c1[i] < c2[i]:
			f = False
			break
		if i != 25:
			c1[i + 1] += c1[i] - c2[i]
	if f == True:
		print('Yes')
	else:
		print('No')


import sys
import os
import math
import copy
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations, accumulate

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def watch(x):
	return print(x)

def common(l1, l2):
	return set(l1).intersection(l2)

def Most_frequent(list):
	return max(set(list), key=list.count)

def solution():
	for _ in range(Int()):
		(n, k) = Mint()
		s = Lstr()
		a = Lstr()
		s = Counter(s)
		a = Counter(a)
		alpha = 'abcdefghijklmnopqrstuvwxy'
		flag = 0
		for i in alpha:
			if s[i] < a[i]:
				flag = 1
				break
			else:
				d = s[i] - a[i]
				if (s[i] - a[i]) % k != 0:
					flag = 1
					break
				s[i] = a[i]
				s[chr(ord(i) + 1)] += d
		if flag == 0:
			if s['z'] != a['z']:
				flag = 1
		if flag == 1:
			print('No')
		else:
			print('Yes')
solution()


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [i for i in input() if i != '\n']
	b = [i for i in input() if i != '\n']
	(alpha1, alpha2) = ([0] * 29, [0] * 29)
	for i in range(n):
		alpha1[ord(a[i]) - 97] += 1
		alpha2[ord(b[i]) - 97] += 1
	for i in range(28):
		if alpha2[i] > alpha1[i] or (alpha1[i] - alpha2[i]) % k != 0:
			print('No')
			break
		defi = alpha1[i] - alpha2[i]
		alpha1[i] -= defi
		alpha1[i + 1] += defi
	else:
		print('Yes')


input = __import__('sys').stdin.readline

def solve(a, b, k, n):
	deca = {}
	decb = {}
	for i in a:
		if i in deca:
			deca[i] += 1
		else:
			deca[i] = 1
	for i in b:
		if i in decb:
			decb[i] += 1
		else:
			decb[i] = 1
	for j in decb:
		if j in deca:
			if deca[j] < decb[j]:
				decb[j] -= deca[j]
				deca[j] = 0
			else:
				deca[j] -= decb[j]
				decb[j] = 0
	for j in decb:
		if decb[j] % k != 0:
			return 'NO'
	for j in deca:
		if deca[j] % k != 0:
			return 'NO'
	q = ''
	p = ''
	for i in decb:
		if decb[i] != 0:
			q += i
	for i in deca:
		if deca[i] != 0:
			p += i
	p = sorted(p)
	q = sorted(q)
	i = 0
	j = 0
	while i < len(p) and j < len(q):
		if p[i] < q[j]:
			if deca[p[i]] < decb[q[j]]:
				decb[q[j]] -= deca[p[i]]
				i += 1
			elif deca[p[i]] == decb[q[j]]:
				i += 1
				j += 1
			else:
				deca[p[i]] -= decb[q[j]]
				j += 1
		else:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input())
	b = list(input())
	print(solve(a, b, k, n))


import sys
import math
from sys import stdin, stdout

def sieve(N):
	primeNumbers = [True] * (N + 1)
	primeNumbers[0] = False
	primeNumbers[1] = False
	i = 2
	while i * i <= N:
		j = i
		if primeNumbers[j]:
			while j * i <= N:
				primeNumbers[j * i] = False
				j += 1
		i += 1
	return primeNumbers

def getPrime(N):
	primes = sieve(N)
	result = []
	for i in range(len(primes)):
		if primes[i]:
			result.append(i)
	return result

def factor(N):
	factors = []
	i = 1
	while i * i <= N:
		if N % i == 0:
			factors.append(i)
			if i != N // i:
				factors.append(N // i)
		i += 1
	return sorted(factors)

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	return gcd(b, a % b)

def extendedGcd(a, b):
	if a < b:
		return extendedGcd(b, a)
	if b == 0:
		return [a, 1, 0]
	res = extendedGcd(b, a % b)
	x = res[2]
	y = res[1] - math.floor(a / b) * res[2]
	res[1] = x
	res[2] = y
	return res

def iterativeModularFunc(a, b, c):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % c
		a = a * a % c
		b = b // 2
	return res

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def Solution(a, b, n, k):
	a1 = [0 for _ in range(26)]
	b1 = [0 for _ in range(26)]
	flag = False
	for c in a:
		a1[ord(c) - ord('a')] += 1
	for c in b:
		b1[ord(c) - ord('a')] += 1
	for i in range(26):
		if a1[i] < b1[i]:
			flag = True
		else:
			d = a1[i] - b1[i]
			if d % k != 0:
				flag = True
			else:
				a1[(i + 1) % 26] += d
	if flag:
		print('NO')
	else:
		print('YES')

def main():
	for _ in range(get_int()):
		(n, k) = get_ints_in_variables()
		a = get_string()
		b = get_string()
		Solution(a, b, n, k)
main()


import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = ['Yes'] * T
for t in range(T):
	(n, k) = map(int, input().split())
	a = input().split()[0]
	b = input().split()[0]
	src = [0] * 26
	for s in a:
		src[ord(s) - ord('a')] += 1
	tgt = [0] * 26
	for s in b:
		tgt[ord(s) - ord('a')] += 1
	for i in range(26):
		if src[i] < tgt[i] or (src[i] - tgt[i]) % k != 0:
			ans[t] = 'No'
			break
		if i < 25:
			src[i + 1] += src[i] - tgt[i]
print(*ans, sep='\n')


from sys import stdin, stdout
from os import path
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
rd = lambda : stdin.readline().strip()
wr = stdout.write
for q in range(int(rd())):
	(a, b) = map(int, rd().split())
	x = rd()
	y = rd()
	first = [0] * 26
	second = [0] * 26
	for i in x:
		first[ord(i) - 97] += 1
	for i in y:
		second[ord(i) - 97] += 1
	for i in range(26):
		if first[i] < second[i] or (first[i] - second[i]) % b:
			wr('No\n')
			break
		if first[i] != second[i] and i + 1 < 26:
			first[i + 1] += first[i] - second[i]
	else:
		wr('Yes\n')


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, K, A, B):
	freqA = Counter(A)
	freqB = Counter(B)
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	assert len(alpha) == 26
	extras = 0
	for i in alpha:
		diff = freqB[i] - freqA[i]
		if diff % K != 0:
			return 'No'
		elif diff > 0:
			if diff > extras:
				return 'No'
			extras -= diff
		elif diff < 0:
			extras += -diff
	if extras != 0:
		return 'No'
	return 'Yes'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, K) = [int(x) for x in input().split()]
	A = input().decode().rstrip()
	B = input().decode().rstrip()
	ans = solve(N, K, A, B)
	print(ans)


import math
from collections import deque
from sys import stdin, stdout, setrecursionlimit
from string import ascii_letters
letters = ascii_letters[:26]
from collections import defaultdict
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	first = input().strip()
	second = input().strip()
	have = defaultdict(int)
	need = defaultdict(int)
	for i in first:
		have[letters.index(i)] += 1
	for i in second:
		need[letters.index(i)] += 1
	ost = 0
	can = True
	for i in range(26):
		if have[i] + ost - need[i] < 0 or (have[i] + ost - need[i]) % k:
			can = False
			break
		ost = have[i] + ost - need[i]
	if ost > 0:
		can = False
	print('Yes\n' if can else 'No\n')


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations, combinations

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = 998244353

def solve():
	(n, k) = mdata()
	a = data()
	b = data()
	d1 = dd(int)
	d2 = dd(int)
	for i in a:
		d1[i] += 1
	for i in b:
		d2[i] += 1
	for i in range(26):
		c = chr(97 + i)
		if d1[c] < d2[c] or (d1[c] - d2[c]) % k != 0:
			return 'No'
		d1[c] -= d2[c]
		d1[chr(97 + i + 1)] += d1[c]
	return 'Yes'
for t in range(int(data())):
	out(solve())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	c = [0] * 26
	for i in input():
		c[ord(i) - 97] += 1
	for i in input():
		c[ord(i) - 97] -= 1
	arr = [i for i in c if i != 0]
	a = 0
	for i in arr:
		if abs(i) % k == 0 and a >= 0:
			a += i
		else:
			print('NO')
			break
	else:
		print('YES')


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
from copy import deepcopy
for _ in range(ii1()):
	(n, k) = iia()
	s = is1()
	ss = is1()
	dic = [0] * 27
	dicc = [0] * 27
	for i in s:
		dic[ord(i) - ord('a')] += 1
	for i in ss:
		dicc[ord(i) - ord('a')] += 1
	flag = True
	ans = ['No', 'Yes']
	for i in range(26):
		if dic[i] < dicc[i] or (dic[i] - dicc[i]) % k:
			flag = False
		dic[i] -= dicc[i]
		dic[i + 1] += dic[i]
	print(ans[flag])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(a, b) = (input()[:-1], input()[:-1])
	cnta = [0] * 27
	cntb = [0] * 27
	for c in a:
		cnta[ord(c) - ord('a')] += 1
	for c in b:
		cntb[ord(c) - ord('a')] += 1
	for i in range(26):
		if cnta[i] < cntb[i] or (cntb[i] - cnta[i]) % k:
			print('No')
			break
		cnta[i + 1] += cnta[i] - cntb[i]
	else:
		print('Yes')


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()

def FACT(n, mod):
	s = 1
	facts = [1]
	for i in range(1, n + 1):
		s *= i
		s %= mod
		facts.append(s)
	return facts[n]

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod
t = II()
for q in range(t):
	(n, k) = MI()
	a = list(SI())
	b = list(SI())
	d1 = [0 for i in range(27)]
	d2 = [0 for i in range(27)]
	for i in range(n):
		d1[ord(a[i]) - 97] += 1
		d2[ord(b[i]) - 97] += 1
	boo = True
	for i in range(25, -1, -1):
		d1[i] += d1[i + 1]
		d2[i] += d2[i + 1]
		if d1[i] > d2[i] or (d2[i] - d1[i]) % k != 0:
			boo = False
			break
	print('Yes' if boo else 'No')


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def cal(s):
	res = [0] * 26
	for c in s:
		res[c - 97] += 1
	return res

def ok():
	cnt = 0
	for (c1, c2) in zip(cc1, cc2):
		d = c1 - c2
		if d == 0:
			continue
		if abs(d) % k:
			return False
		cnt += d // k
		if cnt < 0:
			return False
	return True
for _ in range(II()):
	(n, k) = MI()
	s = BI()
	t = BI()
	cc1 = cal(s)
	cc2 = cal(t)
	if ok():
		print('Yes')
	else:
		print('No')


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = input().split()[0]
	b = input().split()[0]
	d = dd(int)
	for i in a:
		d[i] += 1
	for i in b:
		d[i] -= 1
	lol = 0
	for ii in range(26):
		i = chr(ord('a') + ii)
		if d[i] < 0:
			for jj in range(26):
				ch = chr(ord('a') + jj)
				if ch == i:
					break
				if d[ch] > 0 and d[ch] % k == 0:
					d[i] += d[ch]
					d[ch] = 0
	for i in d:
		if d[i]:
			lol = 1
			break
	if lol:
		print('No')
	else:
		print('Yes')
	t -= 1


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for i in range(I()):
	(n, k) = R()
	a = [0] * 26
	for i in map(lambda x: ord(x) - 97, S()):
		a[i] += 1
	b = [0] * 26
	for i in map(lambda x: ord(x) - 97, S()):
		b[i] += 1
	ans = 'YES'
	for i in range(26):
		if b[i] % k:
			if a[i] % k != b[i] % k:
				ans = 'NO'
				break
			else:
				a[i] -= a[i] % k
				b[i] -= b[i] % k
		if b[i]:
			for j in range(i + 1):
				if not b[i]:
					break
				if a[j]:
					if a[j] % k:
						ans = 'NO'
						break
					else:
						p = min(a[j], b[i])
						a[j] -= p
						b[i] -= p
			if b[i] or ans == 'NO':
				ans = 'NO'
				break
	print(ans)


from sys import stdin, stdout

def alpha_order(c):
	return ord(c) - ord('a')

def solve():
	(n, k) = map(int, input().split())
	a = stdin.readline()
	b = stdin.readline()
	a_alpha = [0] * 26
	b_alpha = [0] * 26
	for i in range(n):
		a_alpha[alpha_order(a[i])] += 1
		b_alpha[alpha_order(b[i])] += 1
	for c in range(26):
		if a_alpha[c] < b_alpha[c]:
			required = (b_alpha[c] - a_alpha[c] + k - 1) // k
			for i in range(c):
				possible = min(a_alpha[i] // k, required)
				a_alpha[i] -= possible * k
				a_alpha[c] += possible * k
				required -= possible
			if required > 0:
				print('No')
				return
		a_alpha[c] -= b_alpha[c]
	print('Yes')

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


def solve(a, b, k, n):
	a.sort()
	b.sort()
	indexA = 0
	indexB = 0
	curr = 0
	while indexA < n and indexB < n:
		if a[indexA] > b[indexB] and curr == 0:
			return 'No'
		elif a[indexA] < b[indexB]:
			if indexA + k - 1 < n and a[indexA + k - 1] == a[indexA]:
				curr += k
				indexA += k
			else:
				return 'No'
		elif a[indexA] > b[indexB] and curr > 0:
			if indexB + k - 1 < n and b[indexB + k - 1] == b[indexB]:
				curr -= k
				indexB += k
			else:
				return 'No'
		else:
			indexA += 1
			indexB += 1
	while indexB < n:
		if indexB + k - 1 < n and b[indexB + k - 1] == b[indexB]:
			curr -= k
			indexB += k
		else:
			return 'No'
	return 'Yes'
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(input())
	b = list(input())
	print(solve(a, b, k, n))


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
inf = float('inf')
mod = int(1000000000.0) + 7
(t,) = gil()
for _ in range(t):
	(n, k) = gil()
	(a, b) = (g(), g())
	(ac, bc) = (Counter(a), Counter(b))
	ans = 'Yes'
	for c in 'abcdefghijklmnopqrstuvwxyz':
		if ac.get(c, 0) < bc.get(c, 0):
			ans = 'No'
			break
		else:
			ac[c] = ac.get(c, 0) - bc.get(c, 0)
			if ac[c] % k:
				ans = 'No'
				break
			if ac[c]:
				nc = chr(ord(c) + 1)
				ac[nc] = ac.get(nc, 0) + ac[c]
	print(ans)


import sys, os
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve_(arr, brr, k):
	x = Counter(arr)
	y = Counter(brr)
	for (bef, aft) in zip('abcdefghijklmnopqrstuvwxy', 'bcdefghijklmnopqrstuvwxyz'):
		if y[bef] > x[bef]:
			return 'No'
		deductible = x[bef] - y[bef]
		if deductible == 0:
			continue
		if deductible % k != 0:
			return 'No'
		x[bef] -= deductible
		x[aft] += deductible
	return 'Yes'

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	pass
ONLINE_JUDGE = False
if os.path.exists('input.txt'):
	ONLINE_JUDGE = True
if ONLINE_JUDGE:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def console(*args):
		pass

def solve(*args):
	return solve_(*args)
if True:
	inp = iter(sys.stdin.readlines())
	input = lambda : next(inp)
else:
	input = sys.stdin.readline
for case_num in range(int(input())):
	(_, k) = list(map(int, input().split()))
	arr = input().strip()
	brr = input().strip()
	res = solve(arr, brr, k)
	print(res)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
from types import GeneratorType
BUFSIZE = 8192

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7
mod = 10 ** 9 + 7
t = int(input())
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def z_array(s1):
	n = len(s1)
	z = [0] * n
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and s1[r - l] == s1[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and s1[r - l] == s1[r]:
					r += 1
				z[i] = r - l
				r -= 1
	return z

def solve():
	l2 = [0] * 27
	for i in s2:
		l2[ord(i) - ord('a')] += 1
	l1 = [0] * 27
	for i in s1:
		l1[ord(i) - ord('a')] += 1
	for j in range(27):
		if l2[j] <= l1[j]:
			l1[j] -= l2[j]
			if l1[j] % k != 0:
				return 'No'
		else:
			l2[j] -= l1[j]
			l1[j] = 0
			cnt = 0
			f_ind = 0
			for i in range(j):
				cnt += l1[i]
				l1[i] = l1[i] % k
			l1[j] = cnt
			if l1[j] >= l2[j]:
				l1[j] -= l2[j]
				if l1[j] % k != 0:
					return 'No'
			else:
				return 'No'
	return 'Yes'
for _ in range(t):
	(n, k) = map(int, input().split())
	s1 = input()
	s2 = input()
	print(solve())


import os
import sys
from io import BytesIO, IOBase
import math
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import cmath, time
start_time = time.time()
MOD = 1000000007
MA = float('inf')
MI = float('-inf')

def increase_stack():
	sys.setrecursionlimit(2 ** 32 // 2 - 1)
	threading.stack_size(1 << 27)
	t = threading.Thread(target=main)
	t.start()
	t.join()

def prints(a):
	print(a, end='')

def binary(n):
	return bin(n)[2:]

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	l.sort()
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countchar(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def str_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def lis(arr):
	n = len(arr)
	lis = [1] * n
	maximum = 0
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				maximum = max(maximum, lis[i])
	return maximum

def lcm(arr):
	a = arr[0]
	val = arr[0]
	for i in range(1, len(arr)):
		gcd = gcd(a, arr[i])
		a = arr[i]
		val *= arr[i]
	return val // gcd

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def inint():
	return int(input())

def inarr():
	return list(map(int, input().split()))

def invar():
	return map(int, input().split())

def instr():
	s = input()
	return list(s)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
TestCases = 1

def solve():
	(_, k) = invar()
	s = input()
	t = input()
	dic = D(int)
	for i in s:
		dic[i] += 1
	for i in t:
		dic[i] -= 1
	a1 = [0] * 26
	a2 = [0] * 26
	for i in dic:
		if dic[i] > 0:
			if dic[i] % k != 0:
				print('NO')
				return
			a1[ord(i) - 97] = dic[i]
		if dic[i] < 0:
			if abs(dic[i]) % k != 0:
				print('NO')
				return
			a2[ord(i) - 97] = abs(dic[i])
	for (i, te) in enumerate(a2):
		if te != 0:
			q = i
			ele = te
			while q > -1 and ele:
				if a1[q] > 0:
					if a1[q] >= ele:
						a1[q] -= ele
						ele = 0
					else:
						ele -= a1[q]
						a1[q] = 0
				q -= 1
			if ele:
				print('NO')
				return
	print('YES')

def main():
	flag = 0
	try:
		sys.stdin = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt', 'r')
		sys.stdout = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt', 'w')
	except:
		flag = 1
	t = 1
	if TestCases:
		t = inint()
	for _ in range(1, t + 1):
		solve()
	if not flag:
		print('Time: %.4f sec' % (time.time() - start_time))
		localtime = time.asctime(time.localtime(time.time()))
		print(localtime)
		sys.stdout.close()
main()


import sys, math
input = sys.stdin.readline
t = int(input())
for tttt in range(t):
	(n, k) = map(int, input().split())
	a = input().strip('\n')
	b = input().strip('\n')
	da = {}
	db = {}
	for i in a:
		try:
			da[i] += 1
		except:
			da[i] = 1
	for i in b:
		try:
			db[i] += 1
		except:
			db[i] = 1
	if a == b:
		print('Yes')
	else:
		flag = True
		for i in db:
			try:
				x = da[i]
				y = db[i]
				da[i] -= min(x, y)
				db[i] -= min(x, y)
			except:
				pass
		for i in db:
			if db[i] % k != 0:
				flag = False
				break
		for i in da:
			if da[i] % k != 0:
				flag = False
				break
		if flag == True:
			l2 = []
			for i in db:
				if db[i] != 0:
					l2.append([i, db[i], 1])
			for i in da:
				if da[i] != 0:
					l2.append([i, da[i], 0])
			l2.sort(key=lambda x: (x[0], x[1]))
			count = 0
			length = len(l2)
			for i in range(length):
				if l2[i][2] == 0:
					count += l2[i][1]
				else:
					count -= l2[i][1]
					if count < 0:
						flag = False
						break
			if count != 0:
				flag = False
			if flag == True:
				print('Yes')
			else:
				print('No')
		else:
			print('No')


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	a = inp()
	b = inp()
	letterA = [0] * 27
	letterB = [0] * 27
	for (i, j) in zip(a, b):
		letterA[ord(i) - 97] += 1
		letterB[ord(j) - 97] += 1
	for i in range(25, -1, -1):
		letterA[i] += letterA[i + 1]
		letterB[i] += letterB[i + 1]
		if (letterB[i] - letterA[i]) % k:
			print('No')
			break
		elif letterA[i] > letterB[i]:
			print('No')
			break
	else:
		print('Yes')


from collections import Counter
import string
import math
import sys
from fractions import Fraction
from itertools import product

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
mod = 10 ** 9 + 7

def comp(x):
	return x[1]

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			primes.append(p * p)
	primes = []

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return -1

def lcm(a, b):
	return a * b // math.gcd(a, b)
mod = 10 ** 9 + 7
testCases = 1
testCases = vary(1)
for _ in range(testCases):
	(n, k) = vary(2)
	a = sys.stdin.readline()
	b = sys.stdin.readline()
	rem = 0
	for i in range(26):
		az = a.count(chr(97 + i))
		az += rem
		bz = b.count(chr(97 + i))
		if az >= bz:
			rem = az - bz
			if (az - bz) % k == 0:
				continue
			else:
				print('NO')
				break
		else:
			print('NO')
			break
	else:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(input().strip())
	b = list(input().strip())
	have = [0] * 26
	need = [0] * 26
	for i in range(n):
		have[ord(a[i]) - 97] += 1
		need[ord(b[i]) - 97] += 1
	bad = True
	for i in range(25):
		xx = have[i] - need[i]
		if xx < 0 or xx % k:
			bad = False
			break
		have[i] = need[i]
		have[i + 1] += xx
	if bad:
		print('Yes')
	else:
		print('No')


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	freq = [0] * 26
	freq1 = [0] * 26
	for i in a:
		freq[ord(i) - ord('a')] += 1
	for i in b:
		freq1[ord(i) - ord('a')] += 1
	ok = True
	add = 0
	for i in range(26):
		if freq[i] == freq1[i]:
			continue
		if freq[i] > freq1[i]:
			extra = freq[i] - freq1[i]
			if extra % k == 0:
				add += extra // k
			else:
				ok = False
				break
		else:
			req = freq1[i] - freq[i]
			if req % k == 0:
				temp = req // k
				if temp <= add:
					add -= temp
				else:
					ok = False
					break
			else:
				ok = False
				break
	if ok and add == 0:
		print('Yes')
	else:
		print('No')


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				n = n // i
				cnt += 1
			tmp.append((i, cnt))
	if n > 1:
		tmp.append((n, 1))
	return tmp

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def main():
	ans = ''
	for _ in range(ii()):
		(n, k) = mi()
		a = I().strip()
		b = I().strip()
		cntA = [0] * 26
		cntB = [0] * 26
		flag = 0
		for i in range(n):
			x = ord(a[i]) - 97
			y = ord(b[i]) - 97
			cntA[x] += 1
			cntB[y] += 1
		for i in range(26):
			if cntA[i] < cntB[i]:
				flag = 1
				break
			cnt = cntA[i] - cntB[i]
			if cnt > 0 and i == 25 or cnt % k > 0:
				flag = 1
				break
			if cnt > 0:
				cntA[i + 1] += cnt
				cntA[i] -= cnt
		if flag == 0:
			ans += 'Yes\n'
		else:
			ans += 'No\n'
	print(ans)
main()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input().strip()
	b = input().strip()
	map1 = [0 for i in range(26)]
	map2 = [0 for j in range(26)]
	for i in a:
		map1[ord(i) - ord('a')] += 1
	for i in b:
		map2[ord(i) - ord('a')] += 1
	c = 0
	for i in range(26):
		if map1[i] % k != map2[i] % k:
			print('NO')
			break
		c += map1[i] // k
		if c and c >= map2[i] // k:
			c -= map2[i] // k
			continue
		if map1[i] != map2[i]:
			print('NO')
			break
	else:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	b = input()
	l = [0] * 26
	z = [0] * 26
	x = ord('a')
	for i in range(n):
		e = ord(a[i])
		l[e - x] += 1
	for i in range(n):
		e = ord(b[i])
		z[e - x] += 1
	f = 0
	for i in range(26):
		if l[i] < z[i]:
			f = 1
			break
		else:
			d = l[i] - z[i]
			if d % k != 0:
				f = 1
				break
			if d != 0:
				l[i + 1] += d
	if f:
		print('No')
	else:
		print('Yes')


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	A = [ord(a) - 97 for a in input()]
	B = [ord(a) - 97 for a in input()]
	C1 = [0] * 26
	C2 = [0] * 26
	for a in A:
		C1[a] += 1
	for a in B:
		C2[a] += 1
	for i in range(26):
		if C1[i] < C2[i] or (C1[i] - C2[i]) % K:
			print('No')
			break
		if C1[i] != C2[i]:
			C1[i + 1] += C1[i] - C2[i]
	else:
		print('Yes')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s1 = input().rstrip()
	s2 = input().rstrip()
	c1 = [0] * 26
	c2 = [0] * 26
	for i in s1:
		c1[ord(i) - 97] += 1
	for i in s2:
		c2[ord(i) - 97] += 1
	ans = 'Yes'
	for i in range(0, 25):
		if c1[i] == 0 and c2[i] == 0:
			continue
		elif c1[i] < c2[i] or (c1[i] - c2[i]) % k > 0:
			ans = 'No'
			break
		c1[i + 1] += c1[i] - c2[i]
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = [int(j) for j in input().split()]
	s = input()
	t = input()
	have = [0] * 27
	need = [0] * 27
	for i in range(n):
		have[ord(s[i]) - 97] += 1
	for i in range(n):
		need[ord(t[i]) - 97] += 1
	flag = True
	for i in range(26):
		if have[i] < need[i] or (have[i] - need[i]) % k != 0:
			flag = False
			break
		have[i + 1] += have[i] - need[i]
	if flag:
		print('YES')
	else:
		print('NO')