#include int a[200005], b[200005]; int p[100005], depth[100005]; int h[200005], l; int comp_h(int x, int y, int z) { if (z == 0) { if (a[h[x]] > a[h[y]]) return 1; else return -1; } else { if (depth[h[x]] < depth[h[y]]) return 1; else return -1; } } void swap_h(int x, int y) { int f = h[x]; h[x] = h[y]; h[y] = f; return; } void push(int ne, int z) { h[l] = ne; int p = l; l++; for (; p > 0; p = (p - 1) / 2) if (comp_h((p - 1) / 2, p, z) > 0) swap_h((p - 1) / 2, p); return; } int pop(int z) { l--; swap_h(0, l); int p = 0; for (;;) { if (2 * p + 2 < l) { if (comp_h(2 * p + 1, 2 * p + 2, z) > 0) { if (comp_h(p, 2 * p + 2, z) > 0) swap_h(p, 2 * p + 2); p = 2 * p + 2; } else { if (comp_h(p, 2 * p + 1, z) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } } else if (2 * p + 1 < l) { if (comp_h(p, 2 * p + 1, z) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } else break; } return h[l]; } int main() { int n, q; scanf("%d %d", &n, &q); int i; for (i = 0; i < n - 1; i++) { i *= 2; scanf("%d %d", &a[i], &b[i]); a[i]--; b[i]--; a[i + 1] = b[i]; b[i + 1] = a[i]; i /= 2; } l = 0; for (i = 0; i < 2 * n - 2; i++) push(i, 0); int c[200005]; for (i = 0; i < 2 * n - 2; i++) c[i] = pop(0); c[2 * n - 2] = 2 * n - 2; a[2 * n - 2] = -1; int min, mid, max; for (i = 0; i < n; i++) p[i] = -1; p[0] = 0; depth[0] = 0; h[0] = 0; l = 1; while (l > 0) { l--; i = h[l]; min = -1; max = 2 * n - 2; while (max - min > 1) { mid = (max + min) / 2; if (a[c[mid]] < i) min = mid; else max = mid; } for (; a[c[max]] == i; max++) { if (p[b[c[max]]] >= 0) continue; p[b[c[max]]] = i; depth[b[c[max]]] = depth[i] + 1; h[l] = b[c[max]]; l++; } } long long int cnt[100005]; for (i = 0; i < n; i++) cnt[i] = 0; l = 0; for (i = 0; i < n; i++) push(i, 1); while (l > 0) { i = pop(1); cnt[i]++; if (i > 0) cnt[p[i]] += cnt[i]; } long long int pp, xx; long long int ans = 0; for (i = 0; i < q; i++) { scanf("%lld %lld", &pp, &xx); ans += cnt[pp - 1] * xx; printf("%lld\n", ans); } return 0; }