// this is the problem of April Lunch Time 2020…
//problem code SHUFFLE
// problem name - Another Birthday Present
#include
#include<bits/stdc++.h>

using namespace std;

bool arraySortedOrNot(int arr[], int n)
{
if (n == 0 || n == 1)
return true;

``````for (int i = 1; i < n; i++)
if (arr[i - 1] > arr[i])
return false;
return true;
``````

}
bool arraySortedOrNot2(int arr[], int n)
{
if (n == 0 || n == 1)
return true;

``````for (int i = 1; i < n; i++)
if (arr[i-1] < arr[i])
return false;
return true;
``````

}
bool compare(int a , int b)
{
return a>b;
}
int main()
{
int T;
cin>>T;
int N, K;
while(T!=0)
{
cin>>N>>K;
int* arr = new int[N];
int* brr = new int[N];

``````    for(int i =1 ; i<=N;i++)
{
cin>>arr[i];
brr[i]=arr[i];
}
for(int i= 1 ;i<=K;i++)
{
vector<int> v1;
for(int j=i; j<=N ;j+=K)
v1.push_back(arr[j]);

sort(v1.begin(), v1.end());
int num=0;
for(int k=i; k<=N ;k+=K)
arr[k]=v1[num++];
}

for(int i=1; i<=K;i++)
{
vector<int> v2;
for(int j=i ; j<N;j+=K)
v2.push_back(brr[i]);

sort(v2.begin(), v2.end(), compare);
int num =0;
for(int k=i; k<N ;k+=K)
brr[k]= v2[num++];
}
bool ans1 = arraySortedOrNot(arr, N);
bool ans2 = arraySortedOrNot2(brr, N);
if(ans1 && ans2)
cout<< "yes"<<endl;
else
cout<< "no"<<endl;

T--;
}
``````

}