Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef got another sequence as a birthday present. He does not like this sequence very much because it is not sorted. Since you are a good programmer, Chef is asking for your help.

You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. You may perform any number of operations of the following type (in any order): choose a valid integer $i$ and swap $A_{i}$ with $A_{i+K}$. Can you sort the sequence this way?

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.

------  Output ------
For each test case, print a single line containing the string "yes" if the sequence can be sorted or "no" otherwise (without quotes).

------  Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ K ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{6}$

------  Subtasks ------
Subtask #1 (50 points): the sequence $A$ is a permutation of the integers $1$ through $N$

Subtask #2 (50 points): original constraints

----- Sample Input 1 ------ 
2

4 1

1 4 2 3

4 2

1 4 2 3
----- Sample Output 1 ------ 
yes

no
----- explanation 1 ------ 
Example case 1: We may freely swap adjacent elements, so the sequence can be sorted e.g. in the following way: $(1, 4, 2, 3) \rightarrow (1, 2, 4, 3) \rightarrow (1, 2, 3, 4)$.

Difficulty: MEDIUM_HARD

Solutions:
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	temp = sorted(arr)
	res = arr
	for i in range(k):
		res[i::k] = sorted(arr[i::k])
	if res == temp:
		print('yes')
	else:
		print('no')


from collections import Counter, defaultdict
import math
import sys
from functools import reduce

def solve(n, l, k):
	d = defaultdict(list)
	for i in range(k):
		for j in range(i, n, k):
			d[i].append(l[j])
		d[i].sort()
	cur = []
	for i in range(n):
		for j in range(k):
			if len(d[j]) <= i:
				break
			cur.append(d[j][i])
	print('yes' if cur == sorted(cur) else 'no')
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	solve(n, arr, k)


import sys
from collections import Counter, deque
from math import gcd, sqrt, ceil

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

def si():
	return sys.stdin.readline().split()

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

def ip():
	return input()
for tastcas in range(int(input())):
	(n, k) = li()
	a = li()
	f = 0
	for i in range(k):
		lst = [a[i]]
		j = i
		try:
			while 1:
				j += k
				lst.append(a[j])
		except:
			lst.sort()
			j = 0
			a[i] = lst[j]
			try:
				while 1:
					i += k
					j += 1
					a[i] = lst[j]
			except:
				pass
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			f = 1
			break
	if f:
		print('no')
	else:
		print('yes')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	for j in range(k):
		l[j::k] = sorted(l[j::k])
	print('yes' if l == sorted(l) else 'no')


for i in range(int(input())):
	(N, K) = map(int, input().split())
	num = list(map(int, input().split()))
	for j in range(K):
		num[j::K] = sorted(num[j::K])
	if num == sorted(num):
		print('yes')
	else:
		print('no')


from sys import stdin, stdout
input = stdin.readline
t = int(input().strip())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	check = sorted(arr)
	biglist = list()
	for i in range(k):
		biglist.append(arr[i:n:k])
	for i in range(len(biglist)):
		biglist[i] = sorted(biglist[i])
	sizes = [len(li) for li in biglist]
	maxi = max(sizes)
	ans = list()
	for j in range(maxi):
		for i in range(len(biglist)):
			if j < sizes[i]:
				ans.append(biglist[i][j])
	if check == ans:
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	swapList = {}
	for index in range(0, n):
		mod = index % k
		listS = swapList.get(mod, -1)
		if listS != -1:
			swapList[mod].append(arr[index])
		else:
			swapList[mod] = [arr[index]]
	size = len(swapList)
	for index in range(size):
		if len(swapList[index]) > 0:
			swapList[index].sort()
	answer = [None] * n
	for index in range(size):
		if len(swapList[index]) > 0:
			start = index
			for j in range(len(swapList[index])):
				answer[start] = swapList[index][j]
				start += k
	check = 0
	for i in range(n - 1):
		if answer[i] <= answer[i + 1]:
			check += 1
	if check == n - 1:
		print('yes')
	else:
		print('no')


from collections import defaultdict as dd
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	if b == 1:
		print('yes')
		continue
	else:
		d = dd(list)
		for j in range(a):
			d[j % b].append(l[j])
		for j in d.keys():
			d[j] = sorted(d[j])
		m = []
		for j in range(a):
			k = d[j % b].pop(0)
			m.append(k)
		l = sorted(l)
		if m == l:
			print('yes')
		else:
			print('no')


for t in range(0, int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))[:n]
	j = sorted(arr)
	c = 0
	res = arr
	for i in range(k):
		res[i::k] = sorted(arr[i::k])
	if res == j:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	res1 = lis.copy()
	res1.sort()
	for j in range(k):
		res = lis[j::k]
		res.sort()
		z = j
		for m in res:
			if res1[z] != m:
				break
			else:
				z += k
		else:
			continue
		break
	else:
		print('yes')
		continue
	print('no')


from heapq import heapify, heappush, heappop
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	dic = {}
	for i in range(k):
		lis = []
		j = 0
		while i + j * k < n:
			lis.append(l[i + j * k])
			j += 1
		dic[i] = lis
	keys = list(dic.keys())
	lenk = k
	for i in keys:
		heapify(dic[i])
	for i in keys:
		j = 0
		lis = dic[i]
		while i + j * k < n:
			l[i + j * k] = heappop(lis)
			j += 1
	flag = True
	for i in range(1, n):
		if l[i] < l[i - 1]:
			flag = False
			break
	if flag:
		print('yes')
	else:
		print('no')


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(k):
		for j in range(i, n, k):
			d[i].append(l[j])
		d[i].sort()
	cur = []
	for i in range(n):
		for j in range(k):
			if len(d[j]) <= i:
				break
			cur.append(d[j][i])
	print('yes' if cur == sorted(cur) else 'no')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	r = sorted(l)
	for i in range(k):
		l[i::k] = sorted(l[i::k])
	print('yes' if l == r else 'no')


a = int(input())
for i in range(a):
	(b, k) = map(int, input().split())
	f = list(map(int, input().split()))
	for i in range(k):
		f[i:b:k] = sorted(f[i:b:k])
	if f == sorted(f):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	srt = sorted(arr)
	Dict = {}
	for st in range(k):
		Dict[st] = []
	st = 0
	retreat = k - 1
	for i in range(n):
		Dict[st].append(srt[i])
		st = 0 if st == retreat else st + 1
	flag = True
	st = 0
	retreat = k - 1
	for i in range(n):
		if arr[i] in Dict[st]:
			st = 0 if st == retreat else st + 1
		else:
			flag = False
			break
	if flag:
		print('yes')
	else:
		print('no')


t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(k):
		a[j::k] = sorted(a[j::k])
	if a == sorted(a):
		print('yes')
	else:
		print('no')


t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	for i in range(k):
		lis1 = lis[i:n:k]
		lis1.sort()
		j = i
		c = 0
		while j < n:
			lis[j] = lis1[c]
			j = j + k
			c += 1
	for i in range(n - 1):
		if lis[i + 1] < lis[i]:
			print('no')
			break
	else:
		print('yes')


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = [int(x) for x in input().split()]
	st = sorted(ar)
	for i in range(k):
		a = [ar[j] for j in range(i, n, k)]
		b = [st[j] for j in range(i, n, k)]
		if Counter(a) != Counter(b):
			print('no')
			break
	else:
		print('yes')


T = int(input())
ans = []
for _ in range(T):
	(N, K) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	lists = [[] for i in range(K)]
	for i in range(N):
		lists[i % K].append(A[i])
	for i in range(len(lists)):
		lists[i].sort()
	new = [0 for i in range(N)]
	for i in range(len(lists)):
		for j in range(len(lists[i])):
			new[i + j * K] = lists[i][j]
	s = ''
	for i in range(N - 1):
		if new[i] > new[i + 1]:
			s = 'no'
			break
	else:
		s = 'yes'
	ans.append(s)
for i in ans:
	print(i)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = a[:]
	s.sort()
	for i in range(k):
		t = [a[j] for j in range(i, n, k)]
		x = [s[z] for z in range(i, n, k)]
		if Counter(t) != Counter(x):
			print('no')
			break
	else:
		print('yes')


import collections
t = int(input().strip())
for i in range(t):
	(n, k) = list(map(int, input().strip().split(' ')))
	a = list(map(int, input().strip().split(' ')))
	s = a.copy()
	s.sort()
	f = 1
	for i in range(0, k):
		t1 = [a[j] for j in range(i, n, k)]
		t2 = [s[j] for j in range(i, n, k)]
		if collections.Counter(t1) != collections.Counter(t2):
			f = 0
			break
	if f == 1:
		print('yes')
	else:
		print('no')


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ls = [int(x) for x in input().split()]
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	arr = ls[:]
	arr.sort()
	for i in range(n):
		d1[ls[i]] = i
		d2[arr[i]] = i
	f = 1
	for j in ls:
		if abs(d1[j] - d2[j]) == 0:
			continue
		elif abs(d1[j] - d2[j]) >= k:
			continue
		else:
			f = 0
			break
	if f == 0:
		print('no')
	else:
		print('yes')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	l2 = []
	p = 0
	for i in range(k):
		p1 = p
		s = []
		while p1 < n:
			s.append(l[p1])
			p1 += k
		l1.append(s)
		p += 1
	for i in range(k):
		l1[i].sort()
	for i in range(len(l1[0])):
		for j in range(k):
			if len(l1[j]) >= i + 1:
				l2.append(l1[j][i])
	l.sort()
	if l2 == l:
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(k):
		a[i::k] = sorted(a[i::k])
	if a == sorted(a):
		print('yes')
	else:
		print('no')


for T in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(k):
		(b, index) = ([], 0)
		for j in range(i, len(a), k):
			b.append(a[j])
		b.sort()
		for j in range(i, len(a), k):
			a[j] = b[index]
			index += 1
	if a == sorted(a):
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	arr = []
	for i in range(0, k):
		arr.append([])
	for i in range(0, n):
		arr[i % k].append(a[i])
	ans = []
	ref = []
	for i in range(0, k):
		arr[i].sort()
	for i in range(0, n):
		ans.append(arr[i % k][i // k])
		ref.append(arr[i % k][i // k])
	ref.sort()
	if ans == ref:
		print('yes')
	else:
		print('no')


import sys

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

def fout(s, sep='\n'):
	sys.stdout.write(str(s) + sep)
t = int(input())
for _ in range(t):
	(n, k) = map(int, fin().split())
	a = [int(x) for x in fin().split()]
	if k == 1:
		print('yes')
		continue
	mapping = {}
	for (index, val) in enumerate(a):
		if val in mapping:
			mapping[val].add(index)
		else:
			mapping[val] = set([index])
	a.sort()
	for i in range(n):
		flag = False
		for index in mapping[a[i]]:
			if abs(index - i) % k == 0:
				mapping[a[i]].remove(index)
				flag = True
				break
		if not flag:
			print('no')
			break
		if i == n - 1:
			print('yes')


t = int(input())
for h in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	li = l.copy()
	li.sort()
	for i in range(k):
		l[i::k] = sorted(l[i::k])
	if len(l) == len(li) and len(l) == sum([1 for (i, j) in zip(l, li) if i == j]):
		print('yes')
	else:
		print('no')


t = int(input())
while t:
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	for i in range(0, k):
		c = 0
		b = []
		for j in range(i, n, k):
			b.append(a[j])
		b.sort()
		for j in range(i, n, k):
			a[j] = b[c]
			c += 1
	for i in range(0, n - 1, 1):
		if a[i] > a[i + 1]:
			print('no')
			break
	else:
		print('yes')
	t = t - 1


def array_swap(arr, i, k):
	if i < k:
		return arr
	while arr[i] < arr[i - k] and i >= k:
		(arr[i], arr[i - k]) = (arr[i - k], arr[i])
		i -= k
	return arr
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if k == 1:
		print('yes')
		continue
	for i in range(n - k):
		if arr[i] > arr[i + k]:
			(arr[i], arr[i + k]) = (arr[i + k], arr[i])
			arr = array_swap(arr, i, k)
	print('yes' if arr == sorted(arr) else 'no')


t = int(input())
for _ in range(t):
	(N, K) = map(int, input().strip().split())
	Seq = list(map(int, input().split()))
	z = Seq.copy()
	z.sort()
	for i in range(K):
		Seq[i::K] = sorted(Seq[i::K])
	if z == Seq:
		print('yes')
	else:
		print('no')


test = int(input())
for _ in range(test):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	dictionary = {}
	for i in range(n):
		temp = i % k
		if temp in dictionary:
			dictionary[temp].append(array[i])
		else:
			dictionary[temp] = [array[i]]
	for i in range(k):
		dictionary[i].sort()
	result = []
	for i in range(n):
		temp = i % k
		if len(dictionary[temp]) == 0:
			continue
		else:
			result.append(dictionary[temp][0])
			dictionary[temp].pop(0)
	flag = 0
	for i in range(n - 1):
		if result[i] > result[i + 1]:
			flag = 1
			break
	if flag == 0:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	h = a.copy()
	h.sort()
	for i in range(k):
		a[i::k] = sorted(a[i::k])
	if h == a:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sorted(arr)
	for i in range(k):
		arr[i::k] = sorted(arr[i::k])
	if arr == s:
		print('yes')
	else:
		print('no')


ted = int(input())
for i in range(ted):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	for i in range(k):
		lis2 = []
		for j in range(i, n, k):
			lis2.append(lis[j])
		lis2.sort()
		sas = 0
		for j in range(i, n, k):
			lis[j] = lis2[sas]
			sas += 1
	state = True
	for i in range(n - 1):
		if lis[i] > lis[i + 1]:
			state = False
			break
	if state:
		print('yes')
	else:
		print('no')


from collections import defaultdict
for x in range(int(input())):
	(n, k) = list(map(int, input().split()))
	m = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(n):
		d[i % k].append(m[i])
	for i in d:
		d[i].sort()
	a = []
	for i in range(n):
		l = i // k
		a.append(d[i % k][l])
	r = 0
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			r = 1
			break
	if r == 0:
		print('yes')
	else:
		print('no')


for k in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	x = [[] for i in range(k)]
	for i in range(n):
		x[i % k].append(l[i])
	for i in range(k):
		x[i].sort()
	l.sort()
	y = [0 for i in range(n)]
	c = [i for i in range(k)]
	for i in range(k):
		for j in x[i]:
			y[c[i]] = j
			c[i] += k
	if l == y:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sorted(l)
	flag = 0
	ind1 = {}
	ind2 = {}
	for i in range(n):
		ind1[l[i]] = i
		ind2[s[i]] = i
	c = 0
	for i in ind1:
		if ind1[i] != ind2[i]:
			if abs(ind1[i] - ind2[i]) < k:
				flag = 1
				break
	if flag == 0:
		print('yes')
	else:
		print('no')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	t = sorted(a).copy()
	dic = {}
	for i in range(n):
		try:
			dic[a[i]].append((i + 1) % k)
		except:
			dic[a[i]] = [(i + 1) % k]
	flag1 = 0
	for i in range(n):
		temp = dic[t[i]]
		flag = 0
		for j in range(len(temp)):
			if temp[j] == (i + 1) % k:
				temp.pop(j)
				flag = 1
				break
		if flag == 0:
			flag1 = 1
			break
	if flag1:
		print('no')
	else:
		print('yes')


def solve():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(k):
		arr[i::k] = sorted(arr[i::k])
	p = sorted(arr)
	if p == arr:
		print('yes')
	else:
		print('no')
t = int(input())
while t != 0:
	solve()
	t -= 1


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	for i in range(k):
		a[i::k] = sorted(a[i::k])
	p = sorted(a)
	if p == a:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = {}
	for i in range(k):
		s[i] = []
	for i in range(n):
		s[i % k].append(l[i])
	for i in range(k):
		s[i].sort()
		c = i
		for j in range(len(s[i])):
			l[c] = s[i][j]
			c += k
	flag = 0
	for i in range(n - 1):
		if l[i] > l[i + 1]:
			flag = 1
			break
	if flag == 1:
		print('no')
	else:
		print('yes')


def inpNum():
	return int(input())

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

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

def binSearch(arr, x, l, r):
	while l <= r:
		m = l + (r - l) // 2
		if arr[m] == x:
			return m
		elif arr[m] > x:
			r = m - 1
		else:
			l = m + 1

def solve():
	(n, k) = inpNums()
	ai = inpList()
	si = ai.copy()
	si.sort()
	for i in range(k):
		(p, q) = ([], [])
		for ii in range(i, n, k):
			p.append(ai[ii])
			q.append(si[ii])
		p.sort()
		if p != q:
			return 'no'
	return 'yes'
for t in range(int(input())):
	print(solve())


T = int(input())
while T:
	T -= 1
	(N, K) = [int(X) for X in input().split(' ')]
	A = [int(X) for X in input().split(' ')]
	A2 = [0 for i in range(N)]
	for i in range(K):
		A3 = sorted(range(i, N, K), key=lambda X: A[X])
		counter = 0
		for j in A3:
			A2[i + K * counter] = A[j]
			counter += 1
	flag = 'yes'
	for i in range(N - 1):
		if A2[i] > A2[i + 1]:
			flag = 'no'
			break
	print(flag)


k = int(input())
for i in range(k):
	s = list(map(int, input().split()))
	m = list(map(int, input().split()))
	for i in range(s[1]):
		j = i
		z = []
		while j < s[0]:
			z.append(m[j])
			j += s[1]
		z.sort()
		j = i
		o = 0
		while j < s[0]:
			m[j] = z[o]
			o += 1
			j += s[1]
		l = 1
	while l < s[0]:
		if m[l] < m[l - 1]:
			break
		l += 1
	if l == s[0]:
		print('yes')
	else:
		print('no')


def binSearch(arr, x, l, r):
	if r >= l:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binSearch(arr, x, l, mid - 1)
		else:
			return binSearch(arr, x, mid + 1, r)
	else:
		return -1
t = int(input())
for _ in range(t):
	(N, K) = [int(i) for i in input().split(' ')]
	arr = [int(i) for i in input().split(' ')]
	temp = arr.copy()
	temp.sort()
	possible = True
	for i in range(N):
		num = arr[i]
		ind = binSearch(temp, num, 0, N - 1)
		back = ind
		front = ind
		found = False
		while True:
			if back < 0 or temp[back] != num:
				break
			if abs(i - back) % K == 0:
				found = True
				break
			back -= 1
		while True:
			if front >= N or temp[front] != num:
				break
			if abs(i - front) % K == 0:
				found = True
				break
			front += 1
		if not found:
			possible = False
			break
	if possible:
		print('yes')
	else:
		print('no')


for test in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(k):
		temp = []
		for j in range(i, n, k):
			temp.append(l[j])
		temp.sort()
		c = 0
		for j in range(i, n, k):
			l[j] = temp[c]
			c += 1
	print('yes' if sorted(l) == l else 'no')


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	x = list(map(int, input().split()))
	for i in range(k):
		x[i::k] = sorted(x[i::k])
	if x == sorted(x):
		print('yes')
	else:
		print('no')
	t = t - 1


t = int(input())
while t:
	t -= 1
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	A = input().split()
	A = [int(ai) for ai in A]
	A_ = list(A)
	A.sort()
	initGrps = [[] for i in range(0, k)]
	for (i, ai) in enumerate(A_):
		grp = (i + 1) % k
		initGrps[grp].append(ai)
	finGrps = [[] for i in range(0, k)]
	for (i, ai) in enumerate(A):
		grp = (i + 1) % k
		finGrps[grp].append(ai)
	ans = True
	for i in range(0, k):
		if sorted(initGrps[i]) != sorted(finGrps[i]):
			ans = False
			break
	if ans:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	dic = {i: ar[i] for i in range(n)}
	dic = dict(sorted(dic.items(), key=lambda x: x[1]))
	dic2 = {}
	ar.sort()
	for i in range(n):
		if ar[i] in dic2:
			dic2[ar[i]].append(i)
		else:
			dic2[ar[i]] = [i]
	i = 0
	fl2 = 1
	for key in dic:
		fl = 1
		for i in dic2[dic[key]]:
			if (key - i) % k == 0:
				fl = 0
				break
		if fl:
			fl2 = 0
			break
	if fl2:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(j) for j in input().split()]
	for j in range(k):
		a[j::k] = sorted(a[j::k])
	if a == sorted(a):
		print('yes')
	else:
		print('no')


def cook(arr, n, k):
	v = []
	for i in range(k):
		for j in range(i, n, k):
			v.append(arr[j])
		v.sort()
		x = 0
		for j in range(i, n, k):
			arr[j] = v[x]
			x += 1
		v = []
	for i in range(n - 1):
		if arr[i] > arr[i + 1]:
			return False
	return True
n = int(input())
for i in range(n):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if cook(l2, l1[0], l1[1]):
		print('yes')
	else:
		print('no')


test = int(input())
for j in range(0, test):
	num = input().split()
	N = int(num[0])
	K = int(num[1])
	lst = [int(y) for y in input().split()]
	sortlst = sorted(lst)
	for i in range(0, K):
		lst[i::K] = sorted(lst[i::K])
	if lst == sortlst:
		print('yes')
	else:
		print('no')


T = int(input())
for t in range(T):
	(N, K) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	sorted_A = sorted(A)
	d = {key: [] for key in A}
	for ele in enumerate(sorted_A):
		d[ele[1]].append(ele[0])
	break_flag = 0
	for seq_seg_ind in range(K):
		if break_flag:
			break
		ind = seq_seg_ind
		while ind < N:
			break_flag = 1
			for val in d[A[ind]]:
				if (val - seq_seg_ind) % K == 0:
					d[A[ind]].remove(val)
					break_flag = 0
					break
			if break_flag:
				break
			ind += K
	if break_flag:
		print('no')
	else:
		print('yes')


try:
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		l = list(map(int, input().split()))
		a = sorted(l)
		for i in range(k):
			l[i::k] = sorted(l[i::k])
		if l == a:
			print('yes')
		else:
			print('no')
except:
	None


T = int(input())
while T > 0:
	(N, K) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(K):
		b = []
		for j in range(i, N, K):
			b.append(a[j])
		b.sort()
		for j in range(i, N, K):
			a[j] = b[(j - i) // K]
	flag = True
	for k in range(1, N):
		if a[k] < a[k - 1]:
			flag = False
			break
	if flag:
		print('yes')
	else:
		print('no')
	T -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l1 = []
	l2 = []
	l3 = []
	i = 0
	while i < n:
		if i % k == 0:
			l1.append(a[i])
			i += 1
		else:
			l2.append(a[i])
			i += 1
	l1.sort()
	l2.sort()
	j = 0
	co1 = 0
	co2 = 0
	while j < n:
		if j % k == 0:
			l3.append(l1[co1])
			co1 += 1
			j += 1
		else:
			l3.append(l2[co2])
			co2 += 1
			j += 1
	if l3 == sorted(a):
		print('yes')
	else:
		print('no')


from sys import stdin
for _ in range(int(stdin.readline())):
	(N, K) = [int(x) for x in stdin.readline().split()]
	A = [int(x) for x in stdin.readline().split()]
	B = sorted(A)
	if K == 1:
		print('yes')
		continue
	flag = True
	for i in range(N // K + 1):
		i1 = B.index(A[i])
		if not abs(i1 - i) % K == 0:
			flag = False
			break
	print('yes') if flag else print('no')