#include<cstdio>
#include<stdlib.h>
struct node{
int *data;
int size;
};
typedef struct node *minheap;
minheap create(int maxsize)
{
minheap h = (minheap)malloc(sizeof(struct node));
h->data = (int*)malloc(sizeof(int)*(maxsize+1));
h->size = 0;
return h;
}
void insert(minheap h,int x)
{
if(!h) return;
int i = ++h->size;
for(;h->data[i/2]>x&&i>1;i/=2){
h->data[i] = h->data[i/2];
}
h->data[i] = x;
}
void path(minheap h,int x)
{
int space = 0;
for(x;x>=1;x/=2){
if(space) printf(" ");
printf("%d",h->data[x]);
space = 1;
}
}
int main()
{
int n,m;
int x;
scanf("%d%d",&n,&m);
minheap h =create(n);
for(int i=0;i<n;i++){
scanf("%d",&x);
insert(h,x);
}
for(int i=0;i<m;i++){
scanf("%d",&x);
path(h,x);
printf("\n");
}
return 0;
}