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 s1=""; int[] genes = new int[n+1]; for(int genes_i=1; genes_i <=n; genes_i++){ String s=in.next(); int l=s.length(); genes[genes_i] = genes[genes_i-1]+l; s1=s1+s; } int[] health = new int[n]; for(int health_i=0; health_i < n; health_i++){ health[health_i] = in.nextInt(); }int max=0,min=Integer.MAX_VALUE; int ss = in.nextInt(); for(int a0 = 0; a0 < ss; a0++){ int first = in.nextInt(); int last = in.nextInt(); String d = in.next(); String s2=s1.substring(first+1,last+2); int ans=0; for(int i=0;imax) max=ans; if(ans