#include <bits/stdc++.h>
using namespace std;
template <int n>
using AI = array<int, n>;
const double eps = 1e-9;
const int oo = 0x3F3F3F3F;
const long long ooLL = 0x3F3F3F3F3F3F3F3FLL;
const int MOD = 1000000007;
template <typename T>
T sqr(T x) {
  return x * x;
}
const double PI = acos(-1.);
long long Round(double x) { return x < 0 ? x - .5 : x + .5; }
int main() {
  void run();
  run();
  return 0;
}
const int N = 1 << 17, T = 600;
int n, q, ty[N], fc[N], c[N], nc, cr[N], crp[N], w[N][2], fv[N], up[N], ti[N],
    to[N], tim;
vector<int> g[N];
vector<pair<int, pair<int, int> > > lo[N], gl[N];
vector<pair<int, int> > vq[N];
long long rs[N], cnt;
void add_(int t, int s) { cnt += w[t][0] * 1LL * w[t][1] * s; }
void add(int v, int s) {
  ;
  ;
  add_(fc[v], -1);
  w[fc[v]][ty[v]] += s;
  add_(fc[v], 1);
}
bool isp(int r, int l) { return ti[r] <= ti[l] && to[l] <= to[r]; }
void addp(int a, int b, int s) {
  ;
  ;
  while (!isp(b, a)) add(b, s), b = up[b];
  while (1) {
    add(a, s);
    if (a == b) break;
    a = up[a];
  }
}
void mc(int v, int pr) {
  c[v] = nc;
  for (auto &t : g[v])
    if (t != pr && !c[t]) mc(t, v);
}
int bld(int v, int pr) {
  int mh = 0;
  ti[v] = tim++;
  up[v] = pr;
  for (auto &t : g[v])
    if (t != pr) mh = max(mh, bld(t, v));
  ++mh;
  if (mh == T || pr == -1) {
    mc(v, pr);
    cr[nc] = v;
    crp[nc] = pr;
    ++nc;
    mh = 0;
  }
  to[v] = tim++;
  return mh;
}
void ca(int b, int v, int pr) {
  add(v, 1);
  for (auto &z : vq[v]) {
    int idx = z.first, a = z.second;
    addp(a, b, 1);
    rs[idx] = cnt;
    ;
    ;
    addp(a, b, -1);
  }
  vq[v].clear();
  for (auto &t : g[v])
    if (t != pr) ca(b, t, v);
  add(v, -1);
}
void run() {
  scanf("%d", &n);
  for (int i = (0), __i(n); i < __i; ++i) scanf("%d", ty + i);
  for (int i = (0), __i(n); i < __i; ++i) scanf("%d", fc + i), fv[i] = fc[i];
  sort(fv, fv + n);
  for (int i = (0), __i(n); i < __i; ++i)
    fc[i] = lower_bound(fv, fv + n, fc[i]) - fv;
  for (int i = (0), __i(n - 1); i < __i; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  nc = 1;
  bld(0, -1);
  for (int ci = (0), __ci(nc); ci < __ci; ++ci) {
    vector<int> z;
    for (int i = (0), __i(n); i < __i; ++i)
      if (c[i] == ci) z.push_back(i);
    ;
    ;
  }
  scanf("%d", &q);
  for (int i = (0), __i(q); i < __i; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a;
    --b;
    if (c[a] > c[b]) swap(a, b);
    (c[a] == c[b] ? lo : gl)[c[a]].push_back({i, {a, b}});
  }
  for (int ci = (1), __ci(nc); ci < __ci; ++ci) {
    for (auto &z : lo[ci]) {
      int idx = z.first, a = z.second.first, b = z.second.second;
      addp(a, b, 1);
      rs[idx] = cnt;
      ;
      ;
      addp(a, b, -1);
    }
    for (auto &z : gl[ci]) {
      int idx = z.first, a = z.second.first, b = z.second.second;
      vq[b].push_back({idx, a});
    }
    if (crp[ci] != -1) ca(cr[ci], crp[ci], cr[ci]);
  }
  for (int i = (0), __i(q); i < __i; ++i) printf("%lld\n", rs[i]);
}
