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;
const int maxn = 500010, inf = 1e9 + 233, mod = 1e9 + 7;
struct edge {
  int too, pre;
} e[maxn << 1];
struct poi {
  int w, pos;
};
vector<poi> v[maxn];
int n, Q, x, y, z, cnt, tot;
int last[maxn], pri[700010], mn[10000010], size[maxn], fa[maxn], dep[maxn],
    son[maxn], top[maxn], a[maxn];
int ans[700010][23], ANS[maxn];
bool vis[10000010];
template <typename T>
inline void read(T &k) {
  int f = 1;
  k = 0;
  char c = getchar();
  while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
  while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
  k *= f;
}
inline void getpri(int n) {
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pri[++cnt] = i, mn[i] = cnt;
    for (int j = 1; 1ll * pri[j] * i <= n; j++) {
      vis[pri[j] * i] = 1;
      if (i % pri[j] == 0) {
        mn[pri[j] * i] = mn[i];
        break;
      }
      mn[pri[j] * i] = j;
    }
  }
}
inline void add(int x, int y) {
  e[++tot] = (edge){y, last[x]};
  last[x] = tot;
}
void dfs1(int x) {
  size[x] = 1;
  for (int i = last[x], too; i; i = e[i].pre)
    if ((too = e[i].too) != fa[x]) {
      dep[too] = dep[x] + 1;
      fa[too] = x;
      dfs1(too);
      size[x] += size[too];
      if (size[son[x]] < size[too]) son[x] = too;
    }
}
void dfs2(int x, int tp) {
  top[x] = tp;
  if (son[x]) dfs2(son[x], tp);
  for (int i = last[x], too; i; i = e[i].pre)
    if ((too = e[i].too) != fa[x] && too != son[x]) dfs2(too, too);
}
inline int lca(int x, int y) {
  int f1 = top[x], f2 = top[y];
  while (f1 != f2) {
    if (dep[f1] < dep[f2]) swap(x, y), swap(f1, f2);
    x = fa[f1];
    f1 = top[x];
  }
  return dep[x] < dep[y] ? x : y;
}
inline void update(int x, int delta) {
  int now = a[x];
  while (now != 1) {
    int p = mn[now], sum = 0;
    while (now % pri[p] == 0) now /= pri[p], sum++;
    long long fac = 1;
    for (int i = 0; i <= sum; i++) ans[p][i] += i * delta, fac *= pri[p];
    int zs = sum;
    while (fac <= 10000000) ans[p][++zs] += sum * delta, fac *= pri[p];
  }
}
inline int power(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * a * ans % mod;
  return ans;
}
void dfs(int x) {
  update(x, 1);
  for (int i = 0; i < v[x].size(); i++) {
    int now = v[x][i].w, fh = now > 0, pos = v[x][i].pos;
    now = abs(now);
    while (now != 1) {
      int p = mn[now], sum = 0;
      while (now % pri[p] == 0) now /= pri[p], sum++;
      if (fh)
        ANS[pos] = 1ll * ANS[pos] * power(pri[p], ans[p][sum]) % mod;
      else
        ANS[pos] =
            1ll * ANS[pos] * power(power(pri[p], ans[p][sum]), mod - 2) % mod;
    }
  }
  for (int i = last[x], too; i; i = e[i].pre)
    if ((too = e[i].too) != fa[x]) dfs(too);
  update(x, -1);
}
int main() {
  getpri(10000000);
  read(n);
  for (int i = 1; i < n; i++) read(x), read(y), add(x, y), add(y, x);
  for (int i = 1; i <= n; i++) read(a[i]);
  dfs1(1);
  dfs2(1, 1);
  read(Q);
  for (int i = 1; i <= Q; i++) {
    read(x);
    read(y);
    read(z);
    v[x].push_back((poi){z, i});
    v[y].push_back((poi){z, i});
    int fq = lca(x, y);
    v[fq].push_back((poi){-z, i});
    fq = fa[fq];
    v[fq].push_back((poi){-z, i});
    ANS[i] = 1;
  }
  dfs(1);
  for (int i = 1; i <= Q; i++) printf("%d\n", ANS[i]);
}