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 PR = 10000007;
int isp[PR], lsp[PR];
void initPR() {
  for (int e = 0; e < PR; e++) isp[e] = 1;
  isp[0] = 0;
  isp[1] = 0;
  for (int e = 2; e < PR; e++) {
    if (isp[e]) {
      lsp[e] = e;
      for (int f = 2 * e; f < PR; f += e) {
        if (lsp[f] == 0) lsp[f] = e;
        isp[f] = 0;
      }
    }
  }
}
vector<pair<int, int> > factors;
void push(int w) {
  factors.clear();
  while (w != 1) {
    if (factors.empty() || factors.back().first != lsp[w])
      factors.push_back({lsp[w], 1});
    else
      factors.back().second++;
    w /= lsp[w];
  }
}
const int mod = 1000000007;
int exponentiation(int a, long long b) {
  int ans = 1;
  for (; b; a = (1ll * a * a) % mod, b >>= 1)
    if (b & 1) ans = (1ll * ans * a) % mod;
  return ans;
}
int gcd(int A, int B) {
  if (B == 0) return A;
  return gcd(B, A % B);
}
const int lg = 24;
const int maxn = 100100;
int lca[lg][maxn], dep[maxn];
map<int, map<int, int> > cnt;
int ans[maxn];
int a[maxn];
void upd(int p) {
  for (auto e : factors) cnt[e.first][e.second] += p;
}
struct event {
  int w, pw, to;
};
vector<event> r[maxn];
vector<int> g[maxn];
int getLca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int e = lg - 1; e >= 0; e--)
    if ((dep[u] - dep[v]) & (1 << e)) u = lca[e][u];
  if (u == v) return u;
  for (int e = lg - 1; e >= 0; e--)
    if (lca[e][u] != lca[e][v]) u = lca[e][u], v = lca[e][v];
  return lca[0][u];
}
void init(int cur, int p) {
  lca[0][cur] = p;
  for (int e = 1; e < lg; e++)
    if (lca[e - 1][cur]) lca[e][cur] = lca[e - 1][lca[e - 1][cur]];
  for (int nxt : g[cur]) {
    if (nxt != p) {
      dep[nxt] = dep[cur] + 1;
      init(nxt, cur);
    }
  }
}
void solve(int cur, int p) {
  push(a[cur]);
  upd(1);
  for (auto e : r[cur]) {
    push(e.w);
    int now = 1;
    for (auto fac : factors) {
      int sum = 0, qtd = 0;
      for (int f = 0; f <= fac.second; f++) sum += f * cnt[fac.first][f];
      for (int f = fac.second + 1; f < lg; f++) qtd += cnt[fac.first][f];
      now = 1ll * now * exponentiation(fac.first, sum) % mod;
      now = 1ll * now * exponentiation(fac.first, qtd * fac.second) % mod;
    }
    now = exponentiation(now, e.pw);
    ans[e.to] = 1ll * ans[e.to] * now % mod;
  }
  for (int nxt : g[cur]) {
    if (nxt != p) {
      solve(nxt, cur);
    }
  }
  push(a[cur]);
  upd(-1);
}
int u[maxn], v[maxn], lc[maxn];
int main() {
  initPR();
  int n;
  scanf("%d", &n);
  for (int e = 0; e < n - 1; e++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int e = 1; e <= n; e++) scanf("%d", a + e);
  init(1, 0);
  int q;
  scanf("%d", &q);
  for (int e = 0; e < q; e++) {
    int w;
    scanf("%d %d %d", u + e, v + e, &w);
    lc[e] = getLca(u[e], v[e]);
    r[lc[e]].push_back({w, 2 * mod - 4, e});
    r[u[e]].push_back({w, 1, e});
    r[v[e]].push_back({w, 1, e});
    ans[e] = gcd(w, a[lc[e]]);
  }
  solve(1, 0);
  for (int e = 0; e < q; e++) printf("%d\n", ans[e]);
  return 0;
}