#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, M;
vector<int> adj[100001];
int weight[100001], gender[100001];
int TIME = 0, START[100001], END[100001];
int L[100001], R[100001], add[100001];
int depth[100001], anc[100001][21];
vector<int> v;
void dfs(int node, int par) {
  anc[node][0] = par;
  v.push_back(node);
  START[node] = TIME;
  TIME++;
  for (int x : adj[node])
    if (x != par) {
      depth[x] = depth[node] + 1;
      dfs(x, node);
    }
  v.push_back(node);
  END[node] = TIME;
  TIME++;
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  int dif = depth[v] - depth[u];
  for (int i = 20; i >= 0; i--)
    if (((1 << i) & dif) != 0) v = anc[v][i];
  if (u == v) return u;
  for (int i = 20; i >= 0; i--)
    if (anc[u][i] != anc[v][i]) {
      u = anc[u][i];
      v = anc[v][i];
    }
  return anc[u][0];
}
int block;
struct query {
  int L;
  int R;
  int add;
  int id;
  query(int a, int b, int c, int d) {
    L = a;
    R = b;
    add = c;
    id = d;
  }
};
bool operator<(query a, query b) {
  int A = (a.L - 1) / block + 1;
  int B = (b.L - 1) / block + 1;
  if (A == B)
    return a.R < b.R;
  else
    return A < B;
}
vector<struct query> queries;
long long boy[100001], girl[100001];
long long cur = 0, ans[100001];
void compress() {
  set<int> st;
  map<int, int> mp;
  for (int i = 1; i <= N; i++) st.insert(weight[i]);
  int counter = 1;
  for (int x : st) {
    mp[x] = counter;
    counter++;
  }
  for (int i = 1; i <= N; i++) weight[i] = mp[weight[i]];
}
bool active[100001];
void insert(int ind);
void del(int ind) {
  if (active[v[ind]] == false) {
    insert(ind);
    return;
  }
  active[v[ind]] = false;
  if (gender[v[ind]]) {
    cur -= girl[weight[v[ind]]];
    boy[weight[v[ind]]]--;
  } else {
    cur -= boy[weight[v[ind]]];
    girl[weight[v[ind]]]--;
  }
}
void insert(int ind) {
  if (active[v[ind]]) {
    del(ind);
    return;
  }
  active[v[ind]] = true;
  if (gender[v[ind]]) {
    cur += girl[weight[v[ind]]];
    boy[weight[v[ind]]]++;
  } else {
    cur += boy[weight[v[ind]]];
    girl[weight[v[ind]]]++;
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &gender[i]);
  for (int i = 1; i <= N; i++) scanf("%d", &weight[i]);
  compress();
  for (int i = 1; i < N; i++) {
    int X, Y;
    scanf("%d%d", &X, &Y);
    adj[X].push_back(Y);
    adj[Y].push_back(X);
  }
  dfs(1, 1);
  for (int i = 1; i <= 20; i++)
    for (int j = 1; j <= N; j++) anc[j][i] = anc[anc[j][i - 1]][i - 1];
  int Q;
  scanf("%d", &Q);
  block = sqrt(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d%d", &L[i], &R[i]);
    if (START[L[i]] > START[R[i]]) swap(L[i], R[i]);
    if (lca(L[i], R[i]) == L[i]) {
      L[i] = START[L[i]];
      R[i] = START[R[i]];
      add[i] = -1;
    } else {
      add[i] = START[lca(L[i], R[i])];
      L[i] = END[L[i]];
      R[i] = START[R[i]];
    }
    queries.push_back(query(L[i], R[i], add[i], i));
  }
  sort(queries.begin(), queries.end());
  for (int i = queries[0].L; i <= queries[0].R; i++) {
    insert(i);
  }
  if (queries[0].add != -1) insert(queries[0].add);
  ans[queries[0].id] = cur;
  if (queries[0].add != -1) del(queries[0].add);
  int l = queries[0].L;
  int r = queries[0].R;
  for (int i = 1; i < (int)queries.size(); i++) {
    while (l < queries[i].L) {
      del(l);
      l++;
    }
    while (r > queries[i].R) {
      del(r);
      r--;
    }
    while (l > queries[i].L) {
      l--;
      insert(l);
    }
    while (r < queries[i].R) {
      r++;
      insert(r);
    }
    if (queries[i].add != -1) insert(queries[i].add);
    ans[queries[i].id] = cur;
    if (queries[i].add != -1) del(queries[i].add);
  }
  for (int i = 0; i < Q; i++) cout << ans[i] << endl;
  return 0;
}
