#include using namespace std; const int N = 100010; int n, m; string s[N], d; typedef long long ll; ll ans1, ans2; typedef pair pp; map cnt[N]; int main() { //freopen("IN.inp", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i=1; i<=n; i++) cin>>s[i]; for(int i=1; i<=n; i++) { ll x; cin>>x; for(map::iterator it = cnt[i-1].begin(); it != cnt[i-1].end(); it++) { pp tmp = *it; cnt[i][tmp.first] = cnt[i-1][tmp.first] + ((tmp.first == s[i]) ? x : 0); } if(cnt[i][s[i]] == 0) cnt[i][s[i]] = x; } cin>>m; for(int i=1; i<=m; i++) { int L, R; ll k = 0; cin>>L>>R>>d; L++, R++; for(int i=0; i