#include<bits/stdc++.h>
using namespace std;
int li[20000005],hsh[20000005],a[20000005],has[20000005];
int h(string s){
int sum=0;
for(int i=0;s[i];i++){
sum=(sum*131+s[i]-'a')%683;
}
int sum2=0;
for(int i=0;s[i];i++){
sum2=(((sum2<<8)+s[i])%911+911)%911;
}
return sum*1000+sum2;
}
void add(string s){
int k=h(s);
hsh[k]=1;
}
void add2(string s){
int k=h(s);
li[k]=1;
}
int main(){
int n,cnt=0;
scanf("%d",&n);
string s;
for(int i=1;i<=n;i++){
cin>>s;
add2(s);
}
int m;
scanf("%d",&m);
for(int i=1;i<=m;i++){
cin>>s;
a[i]=h(s);
if(li[h(s)]!=0&&hsh[h(s)]==0){
cnt++;
}
add(s);
}
int l=0,r=0,now=0,mn=1e9,mx=0;
while(r<=m){
r++;
has[a[r]]++;
if(has[a[r]] == 1&&li[a[r]]){
now++;
mx=max(now,mx);
}
while(now>=cnt){
if(has[a[l]] == 1&&li[a[l]]){
now--;
}
has[a[l]]--;
l++;
if(mx == now){
mn=min(mn,r-l+1);
}
if(mx<now){
mx=now;
mn=r-l+1;
}
}
}
cout<<mx<<endl<<mn;
return 0;
}