#include<iostream>#include<algorithm>#include<math.h>#include<cstring>#include<queue>#include<stack>#include<map>usingnamespace std;int n,m,k;int pre[10090];
map<int,int>visi;intmain(){
cin>>m>>n;
Node *root =NULL;for(int i =0;i<n;i++){
cin>>pre[i];
visi[pre[i]]=1;}while(m--){
int a,b;
cin>>a>>b;if(visi[a]==0&& visi[b]==0)printf("ERROR: %d and %d are not found.\n",a,b);elseif(visi[a]==0)printf("ERROR: %d is not found.\n",a);elseif(visi[b]==0)printf("ERROR: %d is not found.\n",b);else{
int t;for(int j =0;j<n;j++){
t = pre[j];if((pre[j]>=a && pre[j]<=b)||(pre[j]>=b && pre[j]<=a))break;}if(t == a)printf("%d is an ancestor of %d.\n",a,b);elseif(t == b)printf("%d is an ancestor of %d.\n",b,a);elseprintf("LCA of %d and %d is %d.\n",a,b,t);}}return0;}