Problem: Let the main characters of this problem be personages from some recent movie. New Avengers seem to make a lot of buzz. I didn't watch any part of the franchise and don't know its heroes well, but it won't stop me from using them in this problem statement. So, Thanos and Dr. Strange are doing their superhero and supervillain stuff, but then suddenly they stumble across a regular competitive programming problem.

You are given a tree with n vertices.

In each vertex v there is positive integer a_{v}.

You have to answer q queries.

Each query has a from u v x.

You have to calculate ∏_{w ∈ P} gcd(x, a_{w}) mod (10^{9} + 7), where P is a set of vertices on path from u to v. In other words, you are to calculate the product of gcd(x, a_{w}) for all vertices w on the path from u to v. As it might be large, compute it modulo 10^9+7. Here gcd(s, t) denotes the greatest common divisor of s and t.

Note that the numbers in vertices do not change after queries.

I suppose that you are more interested in superhero business of Thanos and Dr. Strange than in them solving the problem. So you are invited to solve this problem instead of them.

Input

In the first line of input there is one integer n (1 ≤ n ≤ 10^{5}) — the size of the tree.

In the next n-1 lines the edges of the tree are described. The i-th edge is described with two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n) and it connects the vertices u_{i} and v_{i}. It is guaranteed that graph with these edges is a tree.

In the next line there are n integers a_1, a_2, …, a_n (1 ≤ a_{v} ≤ 10^{7}).

In the next line there is one integer q (1 ≤ q ≤ 10^{5}) — the number of queries.

And in the next q lines the queries are described. Each query is described with three integers u_{i}, v_{i} and x_{i} (1 ≤ u_{i}, v_{i} ≤ n, 1 ≤ x_{i} ≤ 10^{7}).

Output

Print q numbers — the answers to the queries in the order they are given in the input. Print each answer modulo 10^9+7 = 1000000007. Print each number on a separate line.

Examples

Input

4
1 2
1 3
1 4
6 4 9 5
3
2 3 6
2 3 2
3 4 7


Output

36
4
1


Input

6
1 2
2 3
2 4
1 5
5 6
100000 200000 500000 40000 800000 250000
3
3 5 10000000
6 2 3500000
4 1 64000


Output

196000
12250
999998215

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct Edge {
  int u, v, Next;
} G[100010 * 2];
int head[100010], tot;
inline void add(int u, int v) {
  G[++tot] = (Edge){u, v, head[u]};
  head[u] = tot;
}
int ft[100010][18], h[100010];
int L[100010], R[100010], dfs_clock;
inline void dfs(int x, int fa) {
  L[x] = ++dfs_clock;
  ft[x][0] = fa;
  for (int i = 1; i <= 17; ++i) ft[x][i] = ft[ft[x][i - 1]][i - 1];
  h[x] = h[fa] + 1;
  for (int i = head[x]; i != -1; i = G[i].Next) {
    if (G[i].v == fa) continue;
    dfs(G[i].v, x);
  }
  R[x] = ++dfs_clock;
}
inline int lca(int x, int y) {
  if (h[x] < h[y]) swap(x, y);
  int t = h[x] - h[y];
  for (int i = 17; i >= 0; --i) {
    if (t & (1 << i)) {
      x = ft[x][i];
    }
  }
  if (x == y) return x;
  for (int i = 17; i >= 0; --i) {
    if (ft[x][i] != ft[y][i]) {
      x = ft[x][i];
      y = ft[y][i];
    }
  }
  return ft[x][0];
}
bool vis[10000010];
int pri[2000010], tt;
inline void init(int n) {
  for (int i = 2; i <= n; ++i) {
    if (!vis[i]) {
      pri[++tt] = i;
    }
    for (int j = 1; j <= tot; ++j) {
      if (i * pri[j] > n) break;
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
struct Node {
  int t, x;
  inline bool operator<(const Node& rhs) const { return t < rhs.t; }
};
vector<Node> b[2000100], que[2000100];
int c[2000100];
int q1[100010], q2[100010];
int res[100010];
int C[100010 * 2];
inline void Add(int x, int y) {
  for (; x <= dfs_clock; x += (x & -x)) {
    C[x] += y;
  }
}
inline int query(int x) {
  int ret = 0;
  for (; x; x -= (x & -x)) {
    ret += C[x];
  }
  return ret;
}
inline int Power(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1) ret = 1ll * ret * x % 1000000007;
    x = 1ll * x * x % 1000000007;
    y >>= 1;
  }
  return ret;
}
int ci[100010 * 20];
int main() {
  int n = read();
  memset(head, -1, sizeof(head));
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    add(u, v);
    add(v, u);
  }
  dfs(1, 0);
  init(10000000);
  for (int i = 1; i <= n; ++i) {
    int x = read();
    for (int j = 1; pri[j] * pri[j] <= x; ++j) {
      int cnt = 0;
      while (x % pri[j] == 0) {
        ++cnt;
        x /= pri[j];
      }
      if (cnt) b[j].push_back((Node){cnt, i});
    }
    if (x != 1) {
      int pos = upper_bound(pri + 1, pri + tt + 1, x) - pri - 1;
      b[pos].push_back((Node){1, i});
    }
  }
  int Q = read();
  for (int i = 1; i <= Q; ++i) {
    q1[i] = read(), q2[i] = read();
    int x = read();
    res[i] = 1;
    for (int j = 1; pri[j] * pri[j] <= x; ++j) {
      int cnt = 0;
      while (x % pri[j] == 0) {
        ++cnt;
        x /= pri[j];
      }
      if (cnt) que[j].push_back((Node){cnt, i});
    }
    if (x != 1) {
      int pos = upper_bound(pri + 1, pri + tt + 1, x) - pri - 1;
      que[pos].push_back((Node){1, i});
    }
  }
  for (int t = 1; t <= tt; ++t) {
    if (que[t].size() == 0 || b[t].size() == 0) continue;
    sort(que[t].begin(), que[t].end());
    sort(b[t].begin(), b[t].end());
    ci[0] = 1;
    int li = 0;
    for (int i = 0; i < b[t].size(); ++i) {
      li += b[t][i].t;
      c[i] = 0;
    }
    for (int i = 1; i <= li; ++i) {
      ci[i] = 1ll * ci[i - 1] * pri[t] % 1000000007;
    }
    int now = 0;
    for (int i = 0; i < que[t].size(); ++i) {
      if (now < b[t].size() && (i == 0 || que[t][i].t != que[t][i - 1].t)) {
        for (int j = now; j < b[t].size(); ++j) {
          int lim = min(b[t][j].t, que[t][i].t) - c[j];
          c[j] += lim;
          for (int k = 1; k <= lim; ++k) {
            Add(L[b[t][j].x], 1);
            Add(R[b[t][j].x], -1);
          }
        }
      }
      int X = q1[que[t][i].x], Y = q2[que[t][i].x];
      int LCA = lca(X, Y);
      int A = 0;
      A += query(L[X]);
      A += query(L[Y]);
      A -= query(L[LCA]);
      A -= query(L[ft[LCA][0]]);
      res[que[t][i].x] = 1ll * res[que[t][i].x] * ci[A] % 1000000007;
      while (que[t][i].t > b[t][now].t && now < b[t].size()) ++now;
    }
    for (int i = 0; i < b[t].size(); ++i) {
      for (int j = 1; j <= c[i]; ++j) {
        Add(L[b[t][i].x], -1);
        Add(R[b[t][i].x], 1);
      }
    }
  }
  for (int i = 1; i <= Q; ++i) {
    printf("%d\n", res[i]);
  }
}