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(); } for(int a=0;amax_len) max_len=gene_len; } long max= 0L; long min=Long.MAX_VALUE; int s = in.nextInt(); //start of search for(int a0 = 0; a0 < s; a0++){ //input int first = in.nextInt(); int last = in.nextInt(); String d = in.next(); int i; long total=0L; int k; String exp; int flag=0; int key; //length of d int len=d.length(); //while the whole d is not exhausted for(i=0;i=len) k=len; j=i; flag=0; while(flag==0 && jmax) max=total; if(totalmax) max=total; if(total