#include using namespace std; vector> g; vector d; int dfs( int v, int p ) { int res = 0; for( int x : g[v] ) { if( x == p ) continue; res += dfs( x, v ) + 1; } d[v] = res + 1; return res; } int main() { int N, Q; cin >> N >> Q; g = vector>( N ); d = vector( 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 ); } dfs( 0, -1 ); long long ans = 0; for( int i = 0; i < Q; i++ ) { int p; long long x; cin >> p >> x; p--; ans += d[p] * x; cout << ans << endl; } }