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 getval() {
  char c = getchar();
  int x;
  bool p;
  x = p = 0;
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') p = 1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  if (p) x = -x;
  return x;
}
const int N = 1e5 + 10, M = 1e6 + 10, V = 1e7 + 10, LOG = 18, LOG2 = 25;
const int MOD = 1e9 + 7;
inline int Pow(int a, int k) {
  int ans = 1;
  for (int x = a; k; k >>= 1, x = 1ll * x * x % MOD)
    if (k & 1) ans = 1ll * ans * x % MOD;
  return ans;
}
struct node {
  int u, v, next;
} edge[N << 1];
int last[N], le, a[N];
void add(int u, int v) {
  edge[++le].u = u, edge[le].v = v, edge[le].next = last[u], last[u] = le;
  edge[++le].u = v, edge[le].v = u, edge[le].next = last[v], last[v] = le;
}
int dp[LOG][N], n, deep[N];
void dfs1(int u, int fa) {
  dp[0][u] = fa, deep[u] = deep[fa] + 1;
  for (int i = last[u]; i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs1(v, u);
  }
}
void getdp() {
  for (int i = 1; i < LOG; ++i) {
    for (int j = 1; j <= n; ++j) dp[i][j] = dp[i - 1][dp[i - 1][j]];
  }
}
int getlca(int u, int v) {
  if (deep[u] < deep[v]) swap(u, v);
  for (int i = LOG - 1; ~i; --i)
    if (deep[dp[i][u]] >= deep[v]) u = dp[i][u];
  if (u == v) return u;
  for (int i = LOG - 1; ~i; --i)
    if (dp[i][u] != dp[i][v]) u = dp[i][u], v = dp[i][v];
  return dp[0][u];
}
int id[V], cnt[M][LOG2], lp, x[N], tans[N];
vector<int> qnum[N], qtype[N];
int *s[N * LOG2], ls, pre[N * LOG2];
void qadd(int d, int c) {
  if (!id[d]) id[d] = ++lp;
  s[++ls] = &cnt[id[d]][c], pre[ls] = cnt[id[d]][c];
  ++cnt[id[d]][c];
}
void pop(int to) {
  while (ls != to) *s[ls] = pre[ls], --ls;
}
int qask(int d, int c) {
  if (!id[d]) return 1;
  int now = 1, ans = 1;
  for (int i = 1; i <= c; ++i) {
    now = 1ll * now * d % MOD;
    ans = 1ll * ans * Pow(now, cnt[id[d]][i]) % MOD;
  }
  for (int i = c + 1; i < LOG2; ++i)
    ans = 1ll * ans * Pow(now, cnt[id[d]][i]) % MOD;
  return ans;
}
void dfs2(int u, int fa) {
  int lst = ls;
  for (int d = 2; d * d <= a[u]; ++d)
    if (a[u] % d == 0) {
      int c = 0;
      while (a[u] % d == 0) ++c, a[u] /= d;
      qadd(d, c);
    }
  if (a[u] > 1) qadd(a[u], 1);
  int sz = qnum[u].size();
  for (int i = 0; i < sz; ++i) {
    int num = qnum[u][i], nowx = x[num], type = qtype[u][i], sum = 1;
    for (int d = 2; d * d <= nowx; ++d)
      if (nowx % d == 0) {
        int c = 0;
        while (nowx % d == 0) ++c, nowx /= d;
        sum = 1ll * sum * qask(d, c) % MOD;
      }
    if (nowx > 1 && id[nowx]) sum = 1ll * sum * qask(nowx, 1) % MOD;
    tans[num] = 1ll * tans[num] * (type == 1 ? sum : Pow(sum, MOD - 2)) % MOD;
  }
  for (int i = last[u]; i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs2(v, u);
  }
  pop(lst);
}
int main() {
  n = getval();
  for (int i = 1; i < n; ++i) {
    int u = getval(), v = getval();
    add(u, v);
  }
  dfs1(1, 0);
  getdp();
  for (int i = 1; i <= n; ++i) a[i] = getval();
  int q = getval();
  for (int i = 1; i <= q; ++i) {
    int u = getval(), v = getval(), lca = getlca(u, v);
    x[i] = getval(), tans[i] = 1;
    qnum[u].push_back(i), qtype[u].push_back(1);
    qnum[v].push_back(i), qtype[v].push_back(1);
    qnum[lca].push_back(i), qtype[lca].push_back(-1);
    qnum[dp[0][lca]].push_back(i), qtype[dp[0][lca]].push_back(-1);
  }
  dfs2(1, 0);
  for (int i = 1; i <= q; ++i) printf("%d\n", tans[i]);
  return 0;
}