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() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
bool b[10000000 + 5];
vector<pair<int, pair<int, int> > > v[100000 + 5];
int n, m, last[10000000 + 5], s[10000000 / 5], num, a[100000 + 5],
    head[100000 + 5], cnt;
int fa[16 + 1][100000 + 5], dep[100000 + 5], f[10000000 + 5], Ans[100000 + 5];
struct edge {
  int to, next;
} e[100000 * 2 + 5];
struct eve {
  int a, b, c;
} q[100000 * 30 + 5];
inline int pow(int x, int k) {
  int res = 1;
  for (; k; k >>= 1, x = 1LL * x * x % 1000000007)
    if (k & 1) res = 1LL * res * x % 1000000007;
  return res;
}
inline void ins(int f, int t) {
  e[++cnt] = (edge){t, head[f]};
  head[f] = cnt;
  e[++cnt] = (edge){f, head[t]};
  head[t] = cnt;
}
void dfs(int x, int f) {
  fa[0][x] = f;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != f) dep[e[i].to] = dep[x] + 1, dfs(e[i].to, x);
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int k = dep[x] - dep[y], j = 0; k; k >>= 1, ++j)
    if (k & 1) x = fa[j][x];
  if (x == y) return x;
  for (int i = 16; ~i; --i)
    if (fa[i][x] != fa[i][y]) x = fa[i][x], y = fa[i][y];
  return fa[0][x];
}
void Solve(int x, int fa) {
  for (int t = a[x]; t > 1;)
    for (int p = last[t], y = 1; t % p == 0; t /= p) ++f[y *= p];
  for (int j = 0; j < v[x].size(); ++j)
    q[v[x][j].first].c += v[x][j].second.second * f[v[x][j].second.first];
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) Solve(e[i].to, x);
  for (int t = a[x]; t > 1;)
    for (int p = last[t], y = 1; t % p == 0; t /= p) --f[y *= p];
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) ins(read(), read());
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int j = 2; j <= 10000000; ++j) {
    if (!b[j]) s[++num] = j, last[j] = j;
    for (int i = 1; s[i] * j <= 10000000; ++i) {
      b[s[i] * j] = 1;
      last[s[i] * j] = s[i];
      if (j % s[i] == 0) break;
    }
  }
  dfs(1, 0);
  cnt = 0;
  for (int i = 1; i <= 16; ++i)
    for (int j = 1; j <= n; ++j) fa[i][j] = fa[i - 1][fa[i - 1][j]];
  m = read();
  for (int i = 1; i <= m; ++i) {
    int a = read(), b = read(), c = lca(a, b), x = read();
    Ans[i] = 1;
    while (x > 1) {
      int p = last[x], y = 1;
      q[++cnt] = (eve){i, p, 0};
      while (x % p == 0) {
        x /= p;
        y *= p;
        v[a].push_back(make_pair(cnt, make_pair(y, 1)));
        v[b].push_back(make_pair(cnt, make_pair(y, 1)));
        v[c].push_back(make_pair(cnt, make_pair(y, -1)));
        if (c > 1) v[fa[0][c]].push_back(make_pair(cnt, make_pair(y, -1)));
      }
    }
  }
  Solve(1, 0);
  for (int i = 1; i <= cnt; ++i)
    Ans[q[i].a] = 1LL * Ans[q[i].a] * pow(q[i].b, q[i].c) % 1000000007;
  for (int i = 1; i <= m; ++i) printf("%d\n", Ans[i]);
  return 0;
}