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;
int Pow(int a, int b, int md, int ret = 1) {
  for (; b; b >>= 1, a = 1ll * a * a % md)
    if (b & 1) ret = 1ll * ret * a % md;
  return ret;
}
const int N = 1e5 + 10, MOD = 1e9 + 7, M = 1e7 + 5;
int bp[M], ret[N], C[N * 8][25], P[18][N], H[N], A[N], n, q;
vector<int> adj[N], prs;
vector<array<int, 4>> vec[N];
void preDFS(int v, int p = -1) {
  if (!~p) P[0][v] = 1;
  for (int i = 1; i < 18; i++) P[i][v] = P[i - 1][P[i - 1][v]];
  for (int &u : adj[v]) {
    if (u != p) H[u] = H[v] + 1, P[0][u] = v, preDFS(u, v);
  }
}
int get(int x) { return lower_bound(begin(prs), end(prs), x) - begin(prs); }
int LCA(int u, int v) {
  if (H[u] < H[v]) swap(u, v);
  for (int i = H[u] - H[v]; i; i -= i & -i) u = P[__builtin_ctz(i)][u];
  for (int i = 17; ~i; i--) {
    if (P[i][v] != P[i][u]) u = P[i][u], v = P[i][v];
  }
  return u ^ v ? P[0][v] : v;
}
inline void addQ(int p, int u, int v, int x, int id, int tw) {
  vec[u].push_back({id, 1, x, tw});
  vec[v].push_back({id, 1, x, tw});
  vec[p].push_back({id, -1, x, tw});
  if (p > 1) vec[P[0][p]].push_back({id, -1, x, tw});
}
void DFS(int v, int p = -1) {
  for (int x = A[v]; x > 1; x /= bp[x]) {
    int c = 1;
    for (; bp[x] == bp[x / bp[x]]; x /= bp[x]) c++;
    C[get(bp[x])][c]++;
  }
  for (auto i : vec[v]) {
    int id = i[0], s = i[1], pr = i[2], tw = i[3], x = 0;
    for (int j = 1; j < 25; j++) x += min(tw, j) * C[get(pr)][j];
    if (~s)
      ret[id] = 1ll * ret[id] * Pow(pr, x, MOD) % MOD;
    else
      ret[id] = 1ll * ret[id] * Pow(Pow(pr, x, MOD), MOD - 2, MOD) % MOD;
  }
  for (int &u : adj[v])
    if (u != p) DFS(u, v);
  for (int x = A[v]; x > 1; x /= bp[x]) {
    int c = 1;
    for (; bp[x] == bp[x / bp[x]]; x /= bp[x]) c++;
    C[get(bp[x])][c]--;
  }
}
int main() {
  for (int i = 2; i < M; i++) {
    if (!bp[i])
      for (int j = i; j < M; j += i) bp[j] = i;
  }
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  preDFS(1);
  scanf("%d", &q);
  for (int i = 1; i <= n; i++)
    for (int x = A[i]; x > 1; x /= bp[x])
      if (bp[x] ^ bp[x / bp[x]]) prs.push_back(bp[x]);
  for (int i = 1; i <= q; i++) {
    ret[i] = 1;
    int u, v, x;
    scanf("%d%d%d", &u, &v, &x);
    int p = LCA(u, v);
    for (; x > 1; x /= bp[x]) {
      int c = 1;
      for (; bp[x] == bp[x / bp[x]]; x /= bp[x]) c++;
      prs.push_back(bp[x]);
      addQ(p, u, v, bp[x], i, c);
    }
  }
  sort(begin(prs), end(prs));
  prs.resize(unique(begin(prs), end(prs)) - begin(prs));
  assert((int)prs.size() < 8 * N);
  DFS(1);
  for (int i = 1; i <= q; i++) printf("%d\n", ret[i]);
  return 0;
}