import resource, sys
from bisect import bisect_left
resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1))
sys.setrecursionlimit(10**6)
N = 100000
tin = [0] * N
tout = [0] * N
val = []
sum = [0] * N
level = [[] for i in range(N)]
pref = [[0] for i in range(N)]
h = [0] * N
g = [[] for i in range(N)]
T = 0
def dfs(v, p = -1, d = 0):
global T
h[v] = d
tin[v] = T
T += 1
sum[v] = val[v]
for to in g[v]:
if to != p:
sum[v] += dfs(to, v, d + 1)
level[d].append(tin[v])
pref[d].append(sum[v])
tout[v] = T
T += 1
return sum[v]
n, q = map(int, input().split())
val = list(map(int, input().split()))
for _ in range(n - 1):
u, v = map(int, input().split())
u -= 1
v -= 1
g[u].append(v)
g[v].append(u)
dfs(0)
for i in range(N):
for j in range(1, len(pref[i])):
pref[i][j] += pref[i][j - 1]
for _ in range(q):
v, d = map(int, input().split())
v -= 1
d = h[v] + d + 1
ans = sum[v]
if d < n:
l = bisect_left(level[d], tin[v])
r = bisect_left(level[d], tout[v])
diff = pref[d][r] - pref[d][l]
ans -= diff
print(ans)