local n, q = io.read("*n", "*n") local edge = {} for i = 1, n do edge[i] = {} end for i = 1, n - 1 do local a, b = io.read("*n", "*n") table.insert(edge[a], b) table.insert(edge[b], a) end local tasks = {1} local parent = {} local weight = {} local ccnt = {} for i = 1, n do parent[i] = 0 weight[i] = 1 ccnt[i] = 0 end for i = 1, n do local src = tasks[i] for j = 1, #edge[src] do local dst = edge[src][j] if parent[src] ~= dst then parent[dst] = src table.insert(tasks, dst) ccnt[src] = ccnt[src] + 1 end end end tasks = {} for i = 1, n do if ccnt[i] == 0 then table.insert(tasks, i) end end for i = 1, n do local src = tasks[i] local p = parent[src] if 0 < p then weight[p] = weight[p] + weight[src] ccnt[p] = ccnt[p] - 1 if ccnt[p] == 0 then table.insert(tasks, p) end end end local ret = 0LL for iq = 1, q do local z, x = io.read("*n", "*n") ret = ret + 1LL * x * weight[z] local a = tostring(ret):gsub("LL", "") print(a) end