#include<bits/stdc++.h>
using namespace std;
#define N 100005
long long n,m,mn,ans1,ans2,cnt;
map<string,long long>mp;
map<string,long long>vis;
string s[N],s1[N];
long long two_pointer(){
mn=1e9,cnt=0;
for(long long l=1,r=0;l<=n;l++) {
while(r<m&&cnt<ans1){
r++;
if(mp[s1[r]]==0&&vis[s1[r]]==1) cnt++;
mp[s1[r]]++;
}
if(cnt==ans1&&mn>r-l+1) mn=r-l+1;
if(--mp[s1[l]]==0&&vis[s1[l]]==1) cnt--;
}
return mn;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>s[i];
cin>>m;
for(int i=1;i<=m;i++) cin>>s1[i],mp[s1[i]]++;
for(int i=1;i<=n;i++) if(mp[s[i]]!=0) ans1++,vis[s[i]]=1;
mp.clear();
cout<<ans1<<endl<<two_pointer();
}