#include using namespace std; #define gc getchar_unlocked #define pc putchar_unlocked #define ll long long int #define V_ll vector #define V_int vector #define mp make_pair #define pb push_back #define f first #define s second #define F front #define P pop #define p push #define Pb pop_back #define b begin #define e end #define M_ll multiset #define M_int multiset #define IT iterator #define pii pair #define pll pair #define mh make_heap #define ph push_heap #define Ph pop_heap #define sh sort_heap #define ih is_heap #define p_que priority_queue #define FOR_Z(i,a) for(int i = 0; i < a; ++i) #define FOR_A(i,a,b) for(int i = a; i < b; ++i) #define FOR_O_Z(i,a) for(int i = a; i >= 0; --i) #define FOR_O_A(i,a,b) for(int i = a; i > b; --i) #define mod 1000000007 #define s_l(a) scanf("%lld",&a) #define s_ll(a, b) scanf("%lld %lld",&a, &b) #define s_lll(a, b, c) scanf("%lld %lld %lld",&a, &b, &c) #define s_i(a) scanf("%d",&a) #define s_ii(a, b) scanf("%d %d",&a, &b) #define s_iii(a, b, c) scanf("%d %d %d",&a, &b, &c) #define p_l(a) printf("%lld\n",a) #define p_ll(a, b) printf("%lld %lld\n",a, b) #define p_lll(a, b, c) printf("%lld %lld %lld\n",a, b, c) #define p_i(a) printf("%d\n",a) #define p_ii(a, b) printf("%d %d\n",a, b) #define p_iii(a, b, c) printf("%d %d %d\n",a, b, c) inline int max(int a,int b){return ab?b:a;} inline ll max(ll a,ll b){return ab?b:a;} inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;} inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} const int MOD = 1e9+7; const int N = 1e6+10; const ll inf = 1e18; #define INF 0x3f3f3f3f #define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) typedef pair iPair; ll q_sort (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } //qsort(values, 5, sizeof(int), q_sort); ll power(ll a, ll b) { int f = 1; while(b) { f = b & 1 ? (f * a) % MOD : f; a = (a * a) % MOD; b >>= 1; } return f % MOD; } ll modpow(ll a, ll b) { ll r = 1; while (b) { if (b & 1) { r = (r * a) % mod; } a = (a * a) % mod; b >>= 1; } return r; } ll modpowinverse(ll a) { return modpow(a, mod - 2); } //create method to here void solve() { ll N, health; string DNA, gene; cin>>N; vector v_gene; V_ll v_health; FOR_Z(i, N) { cin>>gene; v_gene.pb(gene); } FOR_Z(i, N) { cin>>health; v_health.pb(health); } ll qType, Mn = 0, Mx = 0, Ft, Lt, sum = 0, diff = 0; cin>>qType; while(qType--) { sum = 0; cin>>Ft>>Lt>>DNA; FOR_A(i, Ft, Lt + 1) { diff = v_gene[i].length(); FOR_Z(j, DNA.length()) { if(v_gene[i] == DNA.substr(j, diff)) { sum += v_health[i]; } //cout<<"V_gene "<>T; while(T--) { solve(); } return 0; } //Determining_DNA_Health.cpp