import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Queue; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); List> list = new ArrayList<>(n); for (int i = 0; i < n; i++) { list.add(new HashMap<>()); } for (int i = 0; i < n - 1; i++) { String[] sa = br.readLine().split(" "); int u = Integer.parseInt(sa[0]); int v = Integer.parseInt(sa[1]); list.get(u).put(v, 0); list.get(v).put(u, 0); } String[] sa = br.readLine().split(" "); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } int q = Integer.parseInt(br.readLine()); int[] x = new int[q]; for (int i = 0; i < q; i++) { x[i] = Integer.parseInt(br.readLine()); } br.close(); PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { Queue que = new ArrayDeque<>(); que.add(x[i]); int[] dep = new int[n]; Arrays.fill(dep, -1); dep[x[i]] = 0; int[] par = new int[n]; Arrays.fill(par, -1); long sum = a[x[i]]; while (!que.isEmpty()) { Integer cur = que.poll(); if (dep[cur] < 2) { Map cmap = list.get(cur); for (int next : cmap.keySet()) { if (dep[next] == -1 && cmap.get(next) < 2 - dep[cur]) { sum += a[next]; a[next] = 0; que.add(next); dep[next] = dep[cur] + 1; par[next] = cur; cmap.put(next, 2 - dep[cur]); list.get(next).put(cur, 0); } } } } a[x[i]] = sum; pw.println(sum); } pw.flush(); } }