#include <bits/stdc++.h>
using namespace std;
const int S = 317;
struct que {
  int st, dr, tpk, lc, id;
};
que Q[100005];
bool cmp(que &q1, que &q2) {
  return (q1.dr / S < q2.dr / S || (q1.dr / S == q2.dr / S && q1.st < q2.st));
}
int lvl[100005], l[100005], r[100005], lin[2 * 100005], par[100005][20],
    tp[100005], nr[100005];
long long sol[100005];
int C[2 * 100005][3];
bool viz[100005];
long long ct = 0;
void DEL(int);
vector<int> graf[100005];
map<int, int> mp;
ifstream fin("test.in");
void dfs(int nod, int tt) {
  lvl[nod] = lvl[tt] + 1;
  l[nod] = ++ct;
  lin[ct] = nod;
  par[nod][0] = tt;
  for (int i = 1; i <= 16; i++) par[nod][i] = par[par[nod][i - 1]][i - 1];
  for (auto vec : graf[nod])
    if (tt != vec) dfs(vec, nod);
  r[nod] = ++ct;
  lin[ct] = nod;
}
int lca(int x, int y) {
  int i;
  if (lvl[x] < lvl[y]) swap(x, y);
  for (i = 16; i >= 0; i--)
    if (lvl[par[x][i]] >= lvl[y]) x = par[x][i];
  for (i = 16; i >= 0; i--)
    if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];
  if (x != y) return par[y][0];
  return x;
}
void AD(int nod) {
  if (viz[nod]) {
    DEL(nod);
    return;
  }
  ct = ct + C[nr[nod]][1 ^ tp[nod]];
  C[nr[nod]][tp[nod]]++;
  viz[nod] = true;
}
void DEL(int nod) {
  if (!viz[nod]) {
    AD(nod);
    return;
  }
  ct = ct - C[nr[nod]][1 ^ tp[nod]];
  C[nr[nod]][tp[nod]]--;
  viz[nod] = false;
}
int main() {
  ios::sync_with_stdio(false);
  int i, x, y, q, lx, rx, n, plc, app = 0;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> tp[i];
  for (i = 1; i <= n; i++) {
    cin >> nr[i];
    if (mp[nr[i]])
      nr[i] = mp[nr[i]];
    else
      mp[nr[i]] = ++app, nr[i] = app;
  }
  for (i = 1; i < n; i++)
    cin >> x >> y, graf[x].push_back(y), graf[y].push_back(x);
  dfs(1, 0);
  cin >> q;
  for (i = 1; i <= q; i++) {
    cin >> x >> y;
    if (l[x] > l[y]) swap(x, y);
    plc = lca(x, y);
    if (plc == x)
      Q[i] = {l[x], l[y], 0, 0, i};
    else
      Q[i] = {r[x], l[y], 1, plc, i};
  }
  sort(Q + 1, Q + q + 1, cmp);
  lx = 1;
  rx = 0;
  ct = 0;
  for (i = 1; i <= q; i++) {
    while (Q[i].st > lx) AD(lin[lx++]);
    while (Q[i].st < lx) DEL(lin[--lx]);
    while (Q[i].dr > rx) AD(lin[++rx]);
    while (Q[i].dr < rx) DEL(lin[rx--]);
    if (Q[i].tpk) AD(Q[i].lc);
    sol[Q[i].id] = ct;
    if (Q[i].tpk) DEL(Q[i].lc);
  }
  for (i = 1; i <= q; i++) cout << sol[i] << '\n';
}
