#include <bits/stdc++.h>

using namespace std;

int main()

{

//write your code here

int t;

cin>>t;

while(t–)

{

int n,k,b;

cin>>n>>k;

int a[n];

if(n>k)

{

b=k;

}

else

{

b=k%n;

}

for(int i=0;i<n;i++)

{

cin>>a[i];

}

if(n%k==0)

{

for(int i=0;i<n;i++)

{

cout<<a[i]<<" “;

}

}

else

{

while(b–)

{

int t=a[n-1];

for(int i=n-1;i>0;i–)

{

a[i]=a[i-1];

}

a[0]=t;

}

for(int i=0;i<n;i++)

{

cout<<a[i]<<” ";

}

}

cout<<endl;

}

return 0;

}

just take an integer i=0

if you have to rotate by k times

make i = n-k

because u eventually need to start printing from n-k digit

then just print n digits and use a[i%n] each time.

so in example

i=n-k = 3

a[i] = 4

a[4%5 ] = 5

a[5%5] = 1

a[6%5 ] = 2

a[7%5 ] = 3

what u got in the end = [4,5,1,2,3]

also make k=k%n before doing all that, because by rotating array of length n - n times, we get back the original array.