import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String[] genes = new String[n]; for(int genes_i=0; genes_i < n; genes_i++){ genes[genes_i] = in.next(); } int[] health = new int[n]; for(int health_i=0; health_i < n; health_i++){ health[health_i] = in.nextInt(); } int s = in.nextInt(); int shealth[]=new int[s]; for(int a0 = 0; a0 < s; a0++){ int first = in.nextInt(); int last = in.nextInt(); String input = in.next(); int numNeedles = 0; for(int j=first;j<=last;j++) { String haystack =input; String needle = ""+genes[j]; int pos = haystack.indexOf(needle); while(pos >= 0 ){ pos = pos + 1; numNeedles = numNeedles + 1; pos = haystack.indexOf(needle,pos); } } shealth[a0]=numNeedles; } Arrays.sort(shealth); System.out.println(shealth[0]+" "+shealth[shealth.length-1]); } }