#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
}*p,*head,*q,*tail;
int main()
{
int n, m, k;
scanf("%d", &n);
while(n--)
{
int l;
scanf("%d %d", &m, &k);
l = m - k;
tail = (struct node *)malloc(sizeof(struct node));
tail->next = NULL;
q = tail;
while(k--)
{
p = (struct node *)malloc(sizeof(struct node));
scanf("%d", &p->data);
p->next = NULL;
q->next = p;
q = p;
}
head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
q = head;
while(l--)
{
p = (struct node *)malloc(sizeof(struct node));
scanf("%d", &p->data);
p->next = NULL;
q->next = p;
q = p;
}
q->next = tail -> next;
q = head;
while(m--)
{
q = q->next;
printf("%d ", q->data);
}
printf("\n");
}
return 0;
}