#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 100000;
vector<int> g[N];
vector<int> level[N];
vector<long long> pref[N];
int tin[N];
int tout[N];
long long sum[N];
int val[N];
int h[N];
int T = 0;
long long dfs(int v, int p = -1, int d = 0)
{
h[v] = d;
tin[v] = T++;
sum[v] = val[v];
for (auto& to : g[v])
{
if (to != p)
{
sum[v] += dfs(to, v, d + 1);
}
}
level[d].push_back(tin[v]);
pref[d].push_back(sum[v]);
tout[v] = T++;
return sum[v];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> val[i];
for (int i = 0; i < n - 1; i++)
{
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 0; i < n; i++) pref[i].push_back(0);
dfs(0);
for (int i = 0; i < n; i++)
for (int j = 1; j < pref[i].size(); j++)
pref[i][j] += pref[i][j - 1];
for (int i = 0; i < q; i++)
{
int v, d;
cin >> v >> d;
v--;
long long ans = sum[v];
int H = h[v] + d + 1;
if (H < n)
{
auto l = lower_bound(level[H].begin(), level[H].end(), tin[v]) - level[H].begin();
auto r = lower_bound(level[H].begin(), level[H].end(), tout[v]) - level[H].begin();
long long diff = pref[H][r] - pref[H][l];
ans -= diff;
}
cout << ans << '\n';
}
return 0;
}