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 long long ksm(long long x, long long y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x % 1000000007)
    if (y & 1) ret = ret * x % 1000000007;
  return ret;
}
vector<int> son[100005], f[10000005 / 10], q1[100005], q2[100005];
int is[10000005], i, j, d, u[30], dep[100005], c[30], tot, cnt, n, q, x, y, v,
    w[100005], p[10000005 >> 3], mn[10000005], fa[100005][17];
long long ans[100005], inv[100005];
void dfs(int now, int fat) {
  dep[now] = dep[fat] + 1;
  fa[now][0] = fat;
  for (int i = 1; i < 17; ++i) fa[now][i] = fa[fa[now][i - 1]][i - 1];
  for (int i = 0, T; i < son[now].size(); ++i)
    if ((T = son[now][i]) != fat) dfs(T, now);
}
void fj(int x) {
  while (x > 1) {
    if (mn[x] == u[tot])
      ++c[tot];
    else
      u[++tot] = mn[x], c[tot] = 1;
    x /= mn[x];
  }
}
void solve(int now) {
  int i, j, k, ps, x;
  tot = 0;
  fj(w[now]);
  for (i = 1; i <= tot; ++i) ++f[is[u[i]]][c[i]];
  for (i = 0; i < q1[now].size(); ++i) {
    ps = q1[now][i];
    tot = 0;
    fj(q2[now][i]);
    if (ps < 0) {
      ps = -ps;
      for (j = 1; j <= tot; ++j) {
        for (k = 1; k < f[is[u[j]]].size(); ++k)
          (inv[ps] *= ksm(u[j], min(k, c[j]) * f[is[u[j]]][k])) %= 1000000007;
      }
    } else {
      for (j = 1; j <= tot; ++j) {
        for (k = 1; k < f[is[u[j]]].size(); ++k)
          (ans[ps] *= ksm(u[j], min(k, c[j]) * f[is[u[j]]][k])) %= 1000000007;
      }
    }
  }
  for (i = 0; i < son[now].size(); ++i)
    if (son[now][i] != fa[now][0]) solve(son[now][i]);
  tot = 0;
  fj(w[now]);
  for (i = 1; i <= tot; ++i) --f[is[u[i]]][c[i]];
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 16; ~i; --i)
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 16; ~i; --i)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int lc;
int main() {
  ios::sync_with_stdio(false);
  for (i = 2; i < 10000005; ++i) {
    if (!is[i]) p[++cnt] = i, is[i] = cnt, mn[i] = i;
    for (j = 1; j <= cnt && (d = i * p[j]) < 10000005; ++j) {
      is[d] = 1;
      mn[d] = p[j];
      if (i % p[j] == 0) break;
    }
  }
  for (i = 1; i <= cnt; ++i)
    for (f[i].push_back(0), j = 1; j <= 10000005 / p[i]; j *= p[i])
      f[i].push_back(0);
  cin >> n;
  for (i = 1; i < n; ++i)
    cin >> x >> y, son[x].push_back(y), son[y].push_back(x);
  for (i = 1; i <= n; ++i) cin >> w[i];
  dfs(1, 0);
  cin >> q;
  for (i = 1; i <= q; ++i) {
    cin >> x >> y >> d, lc = lca(x, y);
    ans[i] = gcd(w[lc], d);
    inv[i] = 1;
    q1[lc].push_back(-i);
    q1[x].push_back(i);
    q1[y].push_back(i);
    q2[lc].push_back(d);
    q2[y].push_back(d);
    q2[x].push_back(d);
  }
  solve(1);
  for (i = 1; i <= q; ++i)
    cout << (ans[i] * ksm(inv[i], 1000000007 - 3)) % 1000000007 << "\n";
}