#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int MAXLog = 20;
struct Query {
  int ind;
  int l, r;
  int lcaInd;
  Query() {}
  Query(int ind, int l, int r) {
    this->ind = ind;
    this->l = l;
    this->r = r;
    this->lcaInd = -1;
  }
  Query(int ind, int l, int r, int lcaInd) : Query(ind, l, r) {
    this->lcaInd = lcaInd;
  }
};
int blockSz;
bool cmp1(Query A, Query B) {
  A.l /= blockSz;
  B.l /= blockSz;
  if (A.l != B.l) return A.l < B.l;
  if (A.r != B.r) return A.r < B.r;
  return A.ind < B.ind;
}
bool cmp2(Query A, Query B) {
  if (A.r != B.r) return A.r < B.r;
  if (A.l != B.l) return A.l < B.l;
  return A.ind < B.ind;
}
int n;
int f[MAXN];
bool sex[MAXN];
int sparse[25][MAXN];
vector<int> graph[MAXN];
int parent[MAXN], depth[MAXN];
int st[MAXN], en[MAXN];
vector<int> seq;
void DFSInit(int x, int last, int level) {
  st[x] = seq.size();
  seq.push_back(x);
  depth[x] = level;
  parent[x] = last;
  for (int y : graph[x]) {
    if (y == last) continue;
    DFSInit(y, x, level + 1);
  }
  en[x] = seq.size();
  seq.push_back(x);
}
int findLCA(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int i = MAXLog; i >= 0; i--) {
    if (sparse[i][v] != -1 && depth[u] <= depth[sparse[i][v]]) v = sparse[i][v];
  }
  if (u == v) return u;
  for (int i = MAXLog; i >= 0; i--) {
    if (sparse[i][u] != sparse[i][v]) {
      u = sparse[i][u];
      v = sparse[i][v];
    }
  }
  return parent[u];
}
void init() {
  map<int, int> code;
  for (int x = 1; x <= n; x++) {
    if (code.count(f[x]) == false) code[f[x]] = code.size() - 1;
    f[x] = code[f[x]];
  }
  DFSInit(1, -1, 1);
  for (int x = 1; x <= n; x++) sparse[0][x] = parent[x];
  for (int i = 1; i <= MAXLog; i++) {
    for (int x = 1; x <= n; x++) {
      if (sparse[i - 1][x] == -1)
        sparse[i][x] = -1;
      else
        sparse[i][x] = sparse[i - 1][sparse[i - 1][x]];
    }
  }
}
struct MOState {
  int l, r;
  int nodeCnt[MAXN];
  int colorCnt[2][MAXN];
  long long answer = 0;
  MOState() {}
  MOState(int l, int r) {
    this->l = l;
    this->r = r;
    memset(this->nodeCnt, 0, sizeof(this->nodeCnt));
    memset(this->colorCnt, 0, sizeof(this->colorCnt));
    this->answer = 0;
  }
  int evalNode(int x) { return colorCnt[sex[x] ^ 1][f[x]]; }
  void processNode(int x, int change) {
    nodeCnt[x] += change;
    if (nodeCnt[x] == 0)
      removeNode(x);
    else if (nodeCnt[x] == 1)
      addNode(x);
    else if (nodeCnt[x] == 2)
      removeNode(x);
  }
  void addNode(int x) {
    colorCnt[sex[x]][f[x]]++;
    answer += evalNode(x);
  }
  void removeNode(int x) {
    colorCnt[sex[x]][f[x]]--;
    answer -= evalNode(x);
  }
};
long long answer[MAXN];
void processQueries(vector<Query> &queries) {
  sort(queries.begin(), queries.end(), cmp2);
  MOState mo(0, -1);
  for (Query q : queries) {
    while (mo.r > q.r) mo.processNode(seq[mo.r], -1), mo.r--;
    while (mo.r < q.r) mo.r++, mo.processNode(seq[mo.r], +1);
    while (mo.l > q.l) mo.l--, mo.processNode(seq[mo.l], +1);
    while (mo.l < q.l) mo.processNode(seq[mo.l], -1), mo.l++;
    if (q.lcaInd == -1)
      answer[q.ind] = mo.answer;
    else {
      mo.addNode(seq[q.lcaInd]);
      answer[q.ind] = mo.answer;
      mo.removeNode(seq[q.lcaInd]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int x = 1; x <= n; x++) cin >> sex[x];
  for (int x = 1; x <= n; x++) cin >> f[x];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  init();
  int Q;
  cin >> Q;
  vector<Query> queries;
  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    if (st[x] > st[y]) swap(x, y);
    int lca = findLCA(x, y);
    if (lca == x) {
      queries.push_back(Query(i, st[x], st[y]));
    } else {
      queries.push_back(Query(i, en[x], st[y], st[lca]));
    }
  }
  blockSz = sqrt(n);
  sort(queries.begin(), queries.end(), cmp1);
  for (int i = 0; i < Q;) {
    int startInd = i;
    vector<Query> v;
    for (; i < Q; i++) {
      if (queries[startInd].l / blockSz != queries[i].l / blockSz) break;
      v.push_back(queries[i]);
    }
    processQueries(v);
  }
  for (int i = 0; i < Q; i++) cout << answer[i] << '\n';
}
