import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.*;
public class Main {
static class Input{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StreamTokenizer in=new StreamTokenizer(br);
public String nextStr() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException{
in.nextToken();
return (int) in.nval;
}
}
static Map<String,Integer> map=new HashMap<>();
static List<String> list=new ArrayList<>();
static int[] nums;
public static void main(String[] args) throws IOException {
Input sc=new Input();
int n=sc.nextInt();
nums=new int[n];
for (int i = 0; i < n; i++) {
String str=sc.nextStr();
if (!map.containsKey(str))
nums[i]=-1;
map.put(str,i);
}
int m=sc.nextInt();
for (int i = 0; i < m; i++) {
list.add(sc.nextStr());
}
int date=map.size();
int ans=Integer.MAX_VALUE;
int key=0;
for (int l=0,r = 0; r < m; r++) {
if (map.containsKey(list.get(r))&&nums[map.get(list.get(r))]++<0){
date--;
key++;
}
if (date==0){
while (!map.containsKey(list.get(l))){
l++;
}
while (map.containsKey(list.get(l))&&nums[map.get(list.get(l))]>0){
nums[map.get(list.get(l++))]--;
}
ans=Math.min(ans,r-l+1);
}
}
System.out.println(key);
if (ans==Integer.MAX_VALUE) System.out.println(0);
else
System.out.println(ans);
}
}