#include using namespace std; using ll = long long; using pint = pair; using pll = pair; void dfs(int v, int p, vector> &G, vector &sz){ if(p != -1 && G[v].size() == 1){ sz[v] = 1; return; } int sum = 0; for(int nv: G[v]){ if(nv == p)continue; dfs(nv, v, G, sz); sum += sz[nv]; } sz[v] = ++sum; } int main(){ int N, Q; cin >> N >> Q; vector> G(N); for(int i = 0; i < N - 1; i++){ int a, b; cin >> a >> b; --a; --b; G[a].push_back(b); G[b].push_back(a); } vector q(Q); for(int i = 0; i < Q; i++){ ll p, x; cin >> p >> x; --p; q[i] = {p, x}; } vector sz(N); dfs(0, -1, G, sz); ll tot = 0; for(int i = 0; i < Q; i++){ ll p, x; tie(p, x) = q[i]; tot += sz[p] * x; cout << tot << endl; } }