
#include<stdio.h>
struct node{
int data;
struct node *next;
struct node *prior;
};
int main()
{
int n,m,k,i,j,h;
struct node *head,*tail,*p,*q;
scanf("%d%d",&n,&m);
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
scanf("%d",&tail->data);
for(i=1;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
tail->next=p;
p->prior=tail;
tail=p;
}
while(m--)
{
scanf("%d",&k);
tail=head;
for(p=tail;p!=NULL;p=p->next)
{
if(p->data==k&&p->next!=NULL&&p->prior!=NULL)
printf("%d %d\n",p->prior->data,p->next->data);
else if(p->data==k&&p->next==NULL&&p->prior!=NULL)
printf("%d\n",p->prior->data);
else if(p->data==k&&p->next!=NULL&&p->prior==NULL)
printf("%d\n",p->next->data);
}
}
}