#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool b1[N];
int Z, num[N], in[N], dp[N][20], dep[N], freq[2][N], f[N];
long long fans[N];
vector<int> g[N], v;
map<int, int> mp;
struct qq {
  int in, l, r, c;
  qq(int a, int b, int e, int d) { in = a, l = b, r = e, c = d; }
  bool operator<(const qq& s) const {
    if (l / Z != s.l / Z) return l / Z < s.l / Z;
    return r / Z < s.r / Z;
  }
};
vector<qq> q;
void dfs(int u, int p, int d) {
  dep[u] = d;
  dp[u][0] = p;
  in[u] = v.size();
  v.push_back(u);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != p) dfs(v, u, d + 1);
  }
  v.push_back(u);
}
int lca(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  int x = dep[a] - dep[b];
  for (int i = 0; i < 20; i++) {
    if ((1 << i) & x) a = dp[a][i];
  }
  if (a == b) return a;
  for (int i = 19; i >= 0; i--) {
    if (dp[a][i] != dp[b][i]) {
      a = dp[a][i], b = dp[b][i];
    }
  }
  return dp[a][0];
}
long long ans;
int l = 0, r = -1;
void add(int in, int d) {
  int x = v[in];
  f[x] += d;
  if (d == 1 && f[x] == 2)
    d = -1;
  else if (d == -1 && f[x] == 1)
    d = 1;
  ans += d * freq[!b1[x]][num[x]];
  freq[b1[x]][num[x]] += d;
}
void fix(int L, int R) {
  while (l < L) {
    add(l, -1);
    l++;
  }
  while (l > L) {
    l--;
    add(l, 1);
  }
  while (r < R) {
    r++;
    add(r, 1);
  }
  while (r > R) {
    add(r, -1);
    r--;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", b1 + i);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", num + i);
    if (mp.find(num[i]) == mp.end()) mp[num[i]] = mp.size();
    num[i] = mp[num[i]];
  }
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    g[a].push_back(b), g[b].push_back(a);
  }
  dfs(1, -1, 0);
  Z = sqrt(v.size() + 0.0) + 1;
  for (int k = 1; k < 20; k++) {
    for (int i = 1; i <= n; i++) {
      if (dp[i][k - 1] == -1)
        dp[i][k] = -1;
      else
        dp[i][k] = dp[dp[i][k - 1]][k - 1];
    }
  }
  int m;
  scanf("%d", &m);
  for (int i = 0, a, b, c; i < m; i++) {
    scanf("%d%d", &a, &b);
    c = lca(a, b);
    bool f = (c != a) & (c != b);
    q.push_back(qq(i, min(in[a], in[b]) + f, max(in[a], in[b]), c * f));
  }
  sort(q.begin(), q.end());
  for (int i = 0; i < m; i++) {
    fix(q[i].l, q[i].r);
    if (q[i].c) add(in[q[i].c], 1);
    fans[q[i].in] = ans;
    if (q[i].c) add(in[q[i].c], -1);
  }
  for (int i = 0; i < m; i++) {
    printf("%I64d\n", fans[i]);
  }
}
