#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long INF = 1e18;
const long double PI = acos(-1);
const long double EPS = 1e-9;
int mod = 998244353;
const int MOD7 = 1000000007;
const int MOD9 = 1000000009;
const int MAXN = 2e5 + 228;
int tin[MAXN];
int cnt[MAXN][2];
int tout[MAXN];
int tl = 0;
vector<int> g[MAXN];
const int lgg = 17;
int up[MAXN][lgg];
int order[MAXN];
void dfs(int v, int p) {
  up[v][0] = p;
  order[tl] = v;
  tin[v] = tl++;
  for (int i = 1; i < lgg; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (int i : g[v]) {
    if (i != p) {
      dfs(i, v);
    }
  }
  order[tl] = v;
  tout[v] = tl++;
}
bool pp(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
  if (pp(a, b)) return a;
  if (pp(b, a)) return b;
  for (int i = lgg - 1; i >= 0; --i)
    if (!pp(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
int f[MAXN];
int tp[MAXN];
int n;
int cum[MAXN];
long long ans = 0;
long long answers[MAXN];
void del(int x, int tp) {
  ans -= cnt[x][tp ^ 1];
  cnt[x][tp]--;
}
void add(int x, int tp) {
  ans += cnt[x][tp ^ 1];
  cnt[x][tp]++;
}
void change(int v) {
  cum[v]++;
  if (cum[v] % 2) {
    add(f[v], tp[v]);
  } else {
    del(f[v], tp[v]);
  }
}
const int bl = 400;
struct query {
  int l, r, i, pt;
};
bool cmp(query a, query b) {
  if (a.l / bl == b.l / bl) {
    if ((a.l / bl) % 2) return a.r < b.r;
    return a.r > b.r;
  }
  return a.l < b.l;
}
vector<query> queries;
signed main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  srand(time(NULL));
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> tp[i];
  for (int i = 1; i <= n; ++i) cin >> f[i];
  vector<int> tf;
  for (int i = 1; i <= n; ++i) tf.push_back(f[i]);
  sort((tf).begin(), (tf).end());
  (tf).resize(unique((tf).begin(), (tf).end()) - tf.begin());
  ;
  for (int i = 1; i <= n; ++i) {
    f[i] = lower_bound((tf).begin(), (tf).end(), f[i]) - tf.begin();
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 1);
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int a, b;
    cin >> a >> b;
    int x = lca(a, b);
    if (tin[a] > tin[b]) swap(a, b);
    if (x == a) {
      queries.push_back({tin[x], tin[b], i, 0});
      continue;
    }
    queries.push_back({tout[a], tin[b], i, x});
  }
  sort((queries).begin(), (queries).end(), cmp);
  int l = 0, r = -1;
  for (auto i : queries) {
    while (l < i.l) change(order[l++]);
    while (l > i.l) change(order[--l]);
    while (r < i.r) change(order[++r]);
    while (r > i.r) change(order[r--]);
    if (i.pt) change(i.pt);
    answers[i.i] = ans;
    if (i.pt) change(i.pt);
  }
  for (int i = 0; i < q; ++i) {
    cout << answers[i] << '\n';
  }
}
