#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#define N 100
#define S_SIZE 40
#define TRIE_SIZE 10000
using namespace std;
struct trie_node{int next[26],no;}trie[TRIE_SIZE];
int visit[N],low[N],n,cnt;
char name[N][S_SIZE],s[S_SIZE];
bool G[N][N];
vector<int>ans;
int getno(int i,int p){
if(!s[i])return trie[p].no;
return getno(i+1,trie[p].next[s[i]-97]);
}
void dfs(int p,int i){
int child=0;
bool is_av=0;
visit[i]=low[i]=++cnt;
for(int j=0;j<n;j++)if(G[i][j]&&j!=p){
if(visit[j])low[i]=min(low[i],visit[j]);
else{
dfs(i,j);
low[i]=min(low[i],low[j]);
if(low[j]>=visit[i])is_av=1;
child++;
}
}
if(i==p&&child>1||i!=p&&is_av)ans.push_back(i);
}
bool ans_cmp(int i,int j){
return strcmp(name[i],name[j])<0;
}
int main(){
for(int t=1;scanf("%d",&n)&&n;t++){
if(t>1)putchar('\n');
int trie_size=1,m;
memset(trie,-1,sizeof(trie));
memset(visit,0,sizeof(visit));
memset(G,0,sizeof(G));
ans.clear();
cnt=0;
for(int i=0;i<n;i++){
int p=0;
scanf("%s",name[i]);
for(int j=0;name[i][j];j++){
if(trie[p].next[name[i][j]-97]==-1)trie[p].next[name[i][j]-97]=trie_size++;
p=trie[p].next[name[i][j]-97];
}
trie[p].no=i;
}
scanf("%d",&m);
for(int i=0;i<m;i++){
int a,b;
scanf("%s",s);
a=getno(0,0);
scanf("%s",s);
b=getno(0,0);
G[a][b]=G[b][a]=1;
}
for(int i=0;i<n;i++)if(!visit[i])dfs(i,i);
sort(ans.begin(),ans.end(),ans_cmp);
printf("City map #%d: %d camera(s) found\n",t,ans.size());
for(int i=0;i<ans.size();i++)puts(name[ans[i]]);
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNpbmNsdWRlPGFsZ29yaXRobT4KI2luY2x1ZGU8dmVjdG9yPgojZGVmaW5lIE4gMTAwCiNkZWZpbmUgU19TSVpFIDQwCiNkZWZpbmUgVFJJRV9TSVpFIDEwMDAwCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnN0cnVjdCB0cmllX25vZGV7aW50IG5leHRbMjZdLG5vO310cmllW1RSSUVfU0laRV07CmludCB2aXNpdFtOXSxsb3dbTl0sbixjbnQ7CmNoYXIgbmFtZVtOXVtTX1NJWkVdLHNbU19TSVpFXTsKYm9vbCBHW05dW05dOwp2ZWN0b3I8aW50PmFuczsKaW50IGdldG5vKGludCBpLGludCBwKXsKICAgIGlmKCFzW2ldKXJldHVybiB0cmllW3BdLm5vOwogICAgcmV0dXJuIGdldG5vKGkrMSx0cmllW3BdLm5leHRbc1tpXS05N10pOwp9CnZvaWQgZGZzKGludCBwLGludCBpKXsKICAgIGludCBjaGlsZD0wOwogICAgYm9vbCBpc19hdj0wOwogICAgdmlzaXRbaV09bG93W2ldPSsrY250OwogICAgZm9yKGludCBqPTA7ajxuO2orKylpZihHW2ldW2pdJiZqIT1wKXsKICAgICAgICBpZih2aXNpdFtqXSlsb3dbaV09bWluKGxvd1tpXSx2aXNpdFtqXSk7CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgZGZzKGksaik7CiAgICAgICAgICAgIGxvd1tpXT1taW4obG93W2ldLGxvd1tqXSk7CiAgICAgICAgICAgIGlmKGxvd1tqXT49dmlzaXRbaV0paXNfYXY9MTsKICAgICAgICAgICAgY2hpbGQrKzsKICAgICAgICB9CiAgICB9CiAgICBpZihpPT1wJiZjaGlsZD4xfHxpIT1wJiZpc19hdilhbnMucHVzaF9iYWNrKGkpOwp9CmJvb2wgYW5zX2NtcChpbnQgaSxpbnQgail7CiAgICByZXR1cm4gc3RyY21wKG5hbWVbaV0sbmFtZVtqXSk8MDsKfQppbnQgbWFpbigpewogICAgZm9yKGludCB0PTE7c2NhbmYoIiVkIiwmbikmJm47dCsrKXsKICAgICAgICBpZih0PjEpcHV0Y2hhcignXG4nKTsKICAgICAgICBpbnQgdHJpZV9zaXplPTEsbTsKICAgICAgICBtZW1zZXQodHJpZSwtMSxzaXplb2YodHJpZSkpOwogICAgICAgIG1lbXNldCh2aXNpdCwwLHNpemVvZih2aXNpdCkpOwogICAgICAgIG1lbXNldChHLDAsc2l6ZW9mKEcpKTsKICAgICAgICBhbnMuY2xlYXIoKTsKICAgICAgICBjbnQ9MDsKICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICAgICAgaW50IHA9MDsKICAgICAgICAgICAgc2NhbmYoIiVzIixuYW1lW2ldKTsKICAgICAgICAgICAgZm9yKGludCBqPTA7bmFtZVtpXVtqXTtqKyspewogICAgICAgICAgICAgICAgaWYodHJpZVtwXS5uZXh0W25hbWVbaV1bal0tOTddPT0tMSl0cmllW3BdLm5leHRbbmFtZVtpXVtqXS05N109dHJpZV9zaXplKys7CiAgICAgICAgICAgICAgICBwPXRyaWVbcF0ubmV4dFtuYW1lW2ldW2pdLTk3XTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0cmllW3BdLm5vPWk7CiAgICAgICAgfQogICAgICAgIHNjYW5mKCIlZCIsJm0pOwogICAgICAgIGZvcihpbnQgaT0wO2k8bTtpKyspewogICAgICAgICAgICBpbnQgYSxiOwogICAgICAgICAgICBzY2FuZigiJXMiLHMpOwogICAgICAgICAgICBhPWdldG5vKDAsMCk7CiAgICAgICAgICAgIHNjYW5mKCIlcyIscyk7CiAgICAgICAgICAgIGI9Z2V0bm8oMCwwKTsKICAgICAgICAgICAgR1thXVtiXT1HW2JdW2FdPTE7CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspaWYoIXZpc2l0W2ldKWRmcyhpLGkpOwogICAgICAgIHNvcnQoYW5zLmJlZ2luKCksYW5zLmVuZCgpLGFuc19jbXApOwogICAgICAgIHByaW50ZigiQ2l0eSBtYXAgIyVkOiAlZCBjYW1lcmEocykgZm91bmRcbiIsdCxhbnMuc2l6ZSgpKTsKICAgICAgICBmb3IoaW50IGk9MDtpPGFucy5zaXplKCk7aSsrKXB1dHMobmFtZVthbnNbaV1dKTsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==