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>
char ch;
bool fs;
void re(int& x) {
  while (ch = getchar(), ch < 33)
    ;
  if (ch == '-')
    fs = 1, x = 0;
  else
    fs = 0, x = ch - 48;
  while (ch = getchar(), ch > 33) x = x * 10 + ch - 48;
  if (fs) x = -x;
}
using namespace std;
int ctt, pri[10000001], di[10000001];
bool vis[10000001];
const int mod = 1000000007;
vector<pair<int, int> > que[700000];
int ans[100001], uu[100001], vv[100001];
int n, q, dfn, s[100001], t[100001], fa[100001], dep[100001], p[100001][17];
int cnt, head[100001], nxt[100001 + 100001], to[100001 + 100001];
void dfs(int u) {
  s[u] = ++dfn;
  p[u][0] = fa[u];
  for (int i = 1; 1 << i <= dep[u]; ++i) p[u][i] = p[p[u][i - 1]][i - 1];
  for (int i = head[u], v; i; i = nxt[i])
    if ((v = to[i]) != fa[u]) {
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs(v);
    }
  t[u] = ++dfn;
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 16; i >= 0; --i)
    if (dep[u] - (1 << i) >= dep[v]) u = p[u][i];
  if (u == v) return u;
  for (int i = 16; i >= 0; --i)
    if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];
  return p[u][0];
}
namespace bit {
const int siz = 100001 + 100001;
int s[siz];
int top, st[10000001];
int ask(int x) {
  int res = 0;
  for (; x; x -= x & -x) res += s[x];
  return res;
}
void add(int x, int y) {
  if (!x) return;
  st[++top] = x;
  for (; x < siz; x += x & -x) s[x] += y;
}
int query(int u, int v) {
  int t = lca(u, v);
  return ask(::s[u]) + ask(::s[v]) - ask(::s[t]) - ask(::s[fa[t]]);
}
void clean() {
  if (top > 10000) {
    top = 0;
    memset(s, 0, sizeof s);
    return;
  }
  for (; top; --top)
    for (int i = st[top]; i < siz; i += i & -i) s[i] = 0;
}
}  // namespace bit
int mi(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}
void init() {
  for (int i = 2; i < 10000001; ++i) {
    if (!vis[i]) {
      pri[++ctt] = i;
      di[i] = ctt;
    }
    for (int j = 1, k; (k = i * pri[j]) < 10000001; ++j) {
      vis[k] = 1;
      di[k] = min(j, di[i]);
      if (i % pri[j] == 0) break;
    }
  }
}
int main() {
  init();
  re(n);
  for (int i = 1, u, v; i < n; ++i) {
    re(u), re(v);
    nxt[++cnt] = head[u], head[u] = cnt, to[cnt] = v;
    nxt[++cnt] = head[v], head[v] = cnt, to[cnt] = u;
  }
  dfs(1);
  for (int i = 1, x; i <= n; ++i) {
    re(x);
    while (x > 1) {
      int cnt = 0, pp = di[x];
      while (x % pri[pp] == 0) {
        x /= pri[pp];
        ++cnt;
        que[pp].push_back(make_pair(cnt, -i));
      }
    }
  }
  re(q);
  for (int i = 1, x; i <= q; ++i) {
    ans[i] = 1;
    re(uu[i]), re(vv[i]), re(x);
    while (x > 1) {
      int cnt = 0, pp = di[x];
      while (x % pri[pp] == 0) {
        x /= pri[pp];
        ++cnt;
      }
      que[pp].push_back(make_pair(cnt, i));
    }
  }
  for (int i = 1; i <= ctt; ++i) {
    sort(que[i].begin(), que[i].end());
    int id;
    for (auto j : que[i])
      if ((id = j.second) > 0)
        ans[id] = 1ll * ans[id] * mi(pri[i], bit::query(uu[id], vv[id])) % mod;
      else
        bit::add(s[-id], 1), bit::add(t[-id], -1);
    bit::clean();
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
}