#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
const int D = 1000, maxn = 110000;
int sex[maxn], f[maxn], par[maxn];
int spec[maxn], root[maxn], used[maxn];
int cnt[2][maxn];
long long ans[maxn];
pair<int, int> qs[maxn];
vector<int> spec_qs[maxn], qs2[maxn];
vector<int> e[maxn];
int dfs_spec(int v, int p) {
  par[v] = p;
  int h = 0;
  for (int u : e[v]) {
    if (u == p) continue;
    uax(h, dfs_spec(u, v));
  }
  if (h > D) {
    h = 0;
    spec[v] = 1;
  }
  return h + 1;
}
void dfs_root(int v, int p) {
  if (spec[v]) root[v] = v;
  for (int u : e[v]) {
    if (u == p) continue;
    root[u] = root[v];
    dfs_root(u, v);
  }
}
long long total = 0;
void change(int i, int delta) {
  total += delta * cnt[sex[i] ^ 1][f[i]];
  cnt[sex[i]][f[i]] += delta;
}
void dfs(int v, int p) {
  change(v, 1);
  ++used[v];
  for (int x : qs2[v]) {
    int y = qs[x].first;
    int w = y;
    while (!used[w]) change(w, 1), w = par[w];
    w = par[w];
    while (w != par[root[y]]) change(w, -1), w = par[w];
    ans[x] = total;
    w = y;
    while (!used[w]) change(w, -1), w = par[w];
    w = par[w];
    while (w != par[root[y]]) change(w, 1), w = par[w];
  }
  for (int u : e[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
  change(v, -1);
  --used[v];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) cin >> sex[i];
  for (int i = 0; i < (int)(n); ++i) cin >> f[i];
  for (int i = 0; i < (int)(n - 1); ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  vector<int> vals(f, f + n);
  sort((vals).begin(), (vals).end());
  vals.erase(unique((vals).begin(), (vals).end()), vals.end());
  for (int i = 0; i < (int)(n); ++i)
    f[i] = lower_bound((vals).begin(), (vals).end(), f[i]) - vals.begin();
  dfs_spec(0, -1);
  spec[0] = 1;
  dfs_root(0, -1);
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    qs[i] = {x, y};
    spec_qs[root[x]].push_back(i);
    ans[i] = -1;
  }
  cerr << "dfs\n";
  for (int i = 0; i < (int)(n); ++i)
    if (spec[i]) {
      for (int x : spec_qs[i])
        if (ans[x] == -1) {
          qs2[qs[x].second].push_back(x);
        }
      dfs(i, -1);
      for (int x : spec_qs[i]) qs2[qs[x].second].clear();
    }
  for (int i = 0; i < (int)(q); ++i) cout << ans[i] << '\n';
  return 0;
}
