#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int MX = 4e7;
char buf[MX];
int c, sz;
void init() {
  c = 0;
  sz = fread(buf, 1, MX, stdin);
}
inline bool II(int &t) {
  while (c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;
  if (c >= sz) return false;
  bool flag = 0;
  if (buf[c] == '-') flag = 1, c++;
  for (t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++)
    t = t * 10 + buf[c] - '0';
  if (flag) t = -t;
  return true;
}
}  // namespace IO
struct Edge {
  int v, next;
} edge[2 * 100010];
int k, head[100010], st[100010], ed[100010], deep[100010], id[2 * 100010],
    anc[100010][20];
int Size, tim, h[100010], a[100010], b[100010], use[100010], girl[100010],
    boy[100010];
long long ans[100010], now;
void add_edge(int u, int v) {
  edge[++k].v = v;
  edge[k].next = head[u];
  head[u] = k;
}
void dfs(int u, int pre) {
  st[u] = ++tim;
  id[tim] = u;
  anc[u][0] = pre;
  deep[u] = deep[pre] + 1;
  for (int i = 1; i <= 16; ++i) anc[u][i] = anc[anc[u][i - 1]][i - 1];
  for (int kk = head[u]; ~kk; kk = edge[kk].next) {
    int v = edge[kk].v;
    if (v == pre) continue;
    dfs(v, u);
  }
  ed[u] = ++tim;
  id[tim] = u;
}
int Lca(int u, int v) {
  int i;
  if (deep[u] < deep[v]) swap(u, v);
  for (i = 16; i >= 0; --i) {
    int t = anc[u][i];
    if (deep[t] >= deep[v]) u = t;
  }
  if (u == v) return v;
  for (i = 16; i >= 0; --i) {
    if (anc[u][i] != anc[v][i]) {
      u = anc[u][i];
      v = anc[v][i];
    }
  }
  return anc[u][0];
}
struct Query {
  int l, r, id, lca;
  bool operator<(const Query &p) const {
    if (l / Size == p.l / Size) return r < p.r;
    return l < p.l;
  }
} q[100010];
inline void XOR(int u) {
  if (!use[u]) {
    use[u] = 1;
    if (h[u]) {
      girl[a[u]]++;
      now += boy[a[u]];
    } else {
      boy[a[u]]++;
      now += girl[a[u]];
    }
  } else {
    use[u] = 0;
    if (h[u]) {
      girl[a[u]]--;
      now -= boy[a[u]];
    } else {
      boy[a[u]]--;
      now -= girl[a[u]];
    }
  }
}
int main() {
  IO::init();
  int n, i, u, v, num, m, lca, l, r;
  IO::II(n);
  for (i = 1; i <= n; ++i) IO::II(h[i]);
  for (i = 1; i <= n; ++i) {
    IO::II(a[i]);
    b[i] = a[i];
  }
  k = -1;
  memset(head, -1, sizeof(head));
  for (i = 1; i < n; ++i) {
    IO::II(u);
    IO::II(v);
    add_edge(u, v);
    add_edge(v, u);
  }
  sort(b + 1, b + 1 + n);
  num = unique(b + 1, b + 1 + n) - b - 1;
  for (i = 1; i <= n; ++i) a[i] = lower_bound(b + 1, b + 1 + num, a[i]) - b;
  Size = (int)(sqrt(2 * n + 9));
  tim = 0;
  dfs(1, 0);
  IO::II(m);
  for (i = 1; i <= m; ++i) {
    IO::II(u);
    IO::II(v);
    if (st[u] > st[v]) swap(u, v);
    lca = Lca(u, v);
    if (u == lca) {
      q[i].l = st[u];
      q[i].r = st[v];
      q[i].id = i;
      q[i].lca = 0;
    } else {
      q[i].l = ed[u];
      q[i].r = st[v];
      q[i].id = i;
      q[i].lca = lca;
    }
  }
  sort(q + 1, q + 1 + m);
  l = 1;
  r = 0;
  now = 0;
  for (i = 1; i <= m; ++i) {
    while (l < q[i].l) XOR(id[l++]);
    while (l > q[i].l) XOR(id[--l]);
    while (r < q[i].r) XOR(id[++r]);
    while (r > q[i].r) XOR(id[r--]);
    if (q[i].lca) XOR(q[i].lca);
    ans[q[i].id] = now;
    if (q[i].lca) XOR(q[i].lca);
  }
  for (i = 1; i <= m; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
