#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
vector<int> p;
map<int, int> mp;
bool check(int x, int u, int v)
{
if(x <= u && x >= v)
return true;
if(x >= u && x <= v)
return true;
if(x == u || x == v)
return true;
return false;
}
int main()
{
int n, m, u, v, x;
while(cin >> n >> m)
{
for(int i = 0; i < m; i++)
{
cin >> x;
p.push_back(x);
mp[x]++;
}
for(int i = 0; i < n; i++)
{
cin >> u >> v;
for(int j = 0; j < m; j++)
{
x = p[j];
if(check(x, u, v))
break;
}
if(mp[u] == mp[v] && mp[u] == 0)
{
printf("ERROR: %d and %d are not found.\n",u, v);
}
else if(mp[u] == 0)
{
printf("ERROR: %d is not found.\n", u);
}
else if(mp[v] == 0)
{
printf("ERROR: %d is not found.\n", v);
}
else
{
if(x == u)
{
printf("%d is an ancestor of %d.\n", x, v);
}
else if(x == v)
{
printf("%d is an ancestor of %d.\n", x, u);
}
else
{
printf("LCA of %d and %d is %d.\n", u, v, x);
}
}
}
}
return 0;
}