#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
vector<int> mp[100005];
int st[100005], ed[100005], cnt;
int a[100005], f[100005];
map<int, int> cmp;
int mo[100005 * 2];
int d[100005], p[100005][20];
void init() {
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i <= n; i++) p[i][j] = p[p[i][j - 1]][j - 1];
}
int lca(int a, int b) {
  if (d[a] > d[b]) swap(a, b);
  int f = d[b] - d[a];
  for (int i = 0; (1 << i) <= f; i++)
    if ((1 << i) & f) b = p[b][i];
  if (a != b) {
    for (int i = 17; i >= 0; i--)
      if (p[a][i] != p[b][i]) {
        a = p[a][i];
        b = p[b][i];
      }
    a = p[a][0];
  }
  return a;
}
void dfs(int x, int pa) {
  st[x] = ++cnt;
  mo[cnt] = x;
  d[x] = d[pa] + 1;
  p[x][0] = pa;
  for (int c : mp[x])
    if (c != pa) {
      dfs(c, x);
    }
  ed[x] = ++cnt;
  mo[cnt] = x;
}
int SZ;
struct mb {
  int l, r, id, a, b, fa;
  void rd(int i) {
    id = i;
    scanf("%d%d", &a, &b);
    fa = lca(a, b);
    if (st[b] < st[a]) swap(a, b);
    if (fa == a) {
      l = st[a];
      r = st[b];
    } else {
      l = ed[a];
      r = st[b];
    }
  }
  bool operator<(const mb &o) const {
    if (l / SZ == o.l / SZ) {
      return l / SZ & 1 ? o.r < r : r < o.r;
    }
    return l / SZ < o.l / SZ;
  }
} q[100005];
int cc[100005], cx[2][100005];
long long ans, Ans[100005];
void add(int pos) {
  int x = mo[pos];
  int sex = a[x];
  if (cc[x] == 0) {
    cc[x]++;
    ans -= (long long)cx[0][f[x]] * cx[1][f[x]];
    cx[sex][f[x]]++;
    ans += (long long)cx[0][f[x]] * cx[1][f[x]];
  } else {
    assert(cc[x] == 1);
    cc[x]++;
    ans -= (long long)cx[0][f[x]] * cx[1][f[x]];
    cx[sex][f[x]]--;
    ans += (long long)cx[0][f[x]] * cx[1][f[x]];
  }
}
void del(int pos) {
  int x = mo[pos];
  int sex = a[x];
  if (cc[x] == 1) {
    cc[x]--;
    ans -= (long long)cx[0][f[x]] * cx[1][f[x]];
    cx[sex][f[x]]--;
    ans += (long long)cx[0][f[x]] * cx[1][f[x]];
  } else {
    assert(cc[x] == 2);
    cc[x]--;
    ans -= (long long)cx[0][f[x]] * cx[1][f[x]];
    cx[sex][f[x]]++;
    ans += (long long)cx[0][f[x]] * cx[1][f[x]];
  }
}
void fmain(int tid) {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", a + i);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", f + i);
  for (int(i) = 1; (i) <= (int)(n); (i)++) cmp[f[i]];
  for (auto &p : cmp) p.second = ++cnt;
  for (int(i) = 1; (i) <= (int)(n); (i)++) f[i] = cmp[f[i]];
  for (int i = 0, u, v; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
  };
  cnt = 0;
  dfs(1, 0);
  init();
  SZ = sqrt(cnt);
  scanf("%d", &m);
  for (int(i) = 1; (i) <= (int)(m); (i)++) q[i].rd(i);
  sort(q + 1, q + 1 + m);
  for (int i = 1, L = 1, R = 0; i <= m; i++) {
    while (R < q[i].r) add(++R);
    while (L > q[i].l) add(--L);
    while (R > q[i].r) del(R--);
    while (L < q[i].l) del(L++);
    if (q[i].fa == q[i].a)
      Ans[q[i].id] = ans;
    else {
      int pos = st[q[i].fa];
      assert(pos < L || R < pos);
      add(pos);
      Ans[q[i].id] = ans;
      del(pos);
    }
  }
  for (int(i) = 1; (i) <= (int)(m); (i)++) printf("%lld\n", Ans[i]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
