#include<iostream>#include<map>usingnamespace std;
map<int,int> m;int a[10100];intmain(){int n, M, x, y, t;
cin >> M >> n;for(int i =0; i < n;++i){
cin >> a[i];
m[a[i]]=1;}while(M--){
cin >> x >> y;for(int j =0; j < n;++j){
t = a[j];if((t > x && t < y)||(t < x && t > y)|| t == x || t == y)break;}if(m[x]==0&& m[y]==0)printf("ERROR: %d and %d are not found.\n", x, y);elseif(m[x]==0|| m[y]==0)printf("ERROR: %d is not found.\n", m[x]==0? x : y);elseif(t != x && t != y)printf("LCA of %d and %d is %d.\n", x, y, t);elseprintf("%d is an ancestor of %d.\n", t, t == x ? y : x);}}