#include <bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
int main(void){
ios::sync_with_stdio(0),cin.tie(0);
int N;
while (cin>>N){
vector<int> cost(N+1),indeg(N+1,0);
vector<int> g[N+1];
vector<pii> v[N+1];
queue<int> q;
for (int i=1 ; i<=N ; i++) cin>>cost[i];
for (int i=1 ; i<=N ; i++){
int cnt,a,b;
cin>>cnt;
while (cnt--){
cin>>a>>b;
v[i].push_back({a,b});
g[a].push_back(i);
indeg[i] += 1;
}
}
for (int i=1 ; i<=N ; i++) if (!indeg[i]) q.push(i);
while (!q.empty()){
int u = q.front();q.pop();
for (auto [idx,cnt] : v[u]){
cost[u] += cost[idx]*cnt;
}
for (int x:g[u]){
indeg[x] -= 1;
if (!indeg[x]) q.push(x);
}
}
for (int i=1 ; i<=N ; i++) cout<<cost[i]<<"\n";
}
}