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 std::map;
using std::pair;
using std::swap;
using std::vector;
const int N = 100010;
const int M = 10000010;
const int MOD = 1e9 + 7;
int _w;
int fpow(int a, int b) {
  int c = 1;
  while (b) {
    if (b & 1) c = int(1LL * a * c % MOD);
    a = int(1LL * a * a % MOD);
    b >>= 1;
  }
  return c;
}
int n, q, qu[N], qv[N], ans[N];
namespace G {
int head[N], nxt[N * 2], to[N * 2], eid;
void init() {
  eid = 0;
  memset(head, -1, sizeof head);
}
void link(int u, int v) {
  to[eid] = v, nxt[eid] = head[u], head[u] = eid++;
  to[eid] = u, nxt[eid] = head[v], head[v] = eid++;
}
}  // namespace G
namespace BIT {
int c[N];
int lb(int x) { return x & (-x); }
void add(int p, int x) {
  for (; p <= n; p += lb(p)) c[p] += x;
}
int sum(int p) {
  int s = 0;
  for (; p; p -= lb(p)) s += c[p];
  return s;
}
int sum(int l, int r) { return sum(r) - sum(l - 1); }
}  // namespace BIT
namespace HLD {
int dfn[N], clk, top[N], sz[N], son[N], pa[N], dep[N];
void init1(int u, int fa, int d) {
  using namespace G;
  sz[u] = 1, dep[u] = d, pa[u] = fa, son[u] = 0;
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = to[i];
    if (fa == v) continue;
    init1(v, u, d + 1);
    sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}
void init2(int u, int tp) {
  using namespace G;
  dfn[u] = ++clk, top[u] = tp;
  if (son[u]) init2(son[u], tp);
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = to[i];
    if (v == pa[u] || v == son[u]) continue;
    init2(v, v);
  }
}
void init() {
  clk = 0;
  init1(1, 0, 1);
  init2(1, 1);
}
int query(int u, int v) {
  int s = 0;
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    s += BIT::sum(dfn[top[u]], dfn[u]);
    u = pa[top[u]];
  }
  if (dep[u] > dep[v]) swap(u, v);
  s += BIT::sum(dfn[u], dfn[v]);
  return s;
}
void add(int u, int x) { BIT::add(dfn[u], x); }
}  // namespace HLD
int isp[M], prm[M], pn;
void prelude() {
  memset(isp, 1, sizeof isp);
  isp[0] = isp[1] = 0;
  for (int i = 2; i < M; ++i)
    if (isp[i])
      for (long long j = 1LL * i * i; j < M; j += i) isp[j] = 0;
  for (int i = 2; i < M; ++i)
    if (isp[i]) prm[pn++] = i;
}
map<int, vector<pair<int, int> > > fac, qry;
void solve() {
  for (map<int, vector<pair<int, int> > >::iterator it = fac.begin();
       it != fac.end(); ++it) {
    int p = it->first;
    if (!qry.count(p)) continue;
    vector<pair<int, int> > &qvec = qry[p], &vec = it->second;
    sort(qvec.begin(), qvec.end());
    sort(vec.begin(), vec.end());
    vector<pair<int, int> >::iterator qit = qvec.begin();
    for (vector<pair<int, int> >::iterator vit = vec.begin(); vit != vec.end();
         ++vit) {
      while (qit != qvec.end() && vit->first > qit->first) {
        int id = qit->second;
        int cnt = HLD::query(qu[id], qv[id]);
        ans[id] = int(1LL * ans[id] * fpow(p, cnt) % MOD);
        ++qit;
      }
      HLD::add(vit->second, 1);
    }
    while (qit != qvec.end()) {
      int id = qit->second;
      int cnt = HLD::query(qu[id], qv[id]);
      ans[id] = int(1LL * ans[id] * fpow(p, cnt) % MOD);
      ++qit;
    }
    for (vector<pair<int, int> >::iterator vit = vec.begin(); vit != vec.end();
         ++vit)
      HLD::add(vit->second, -1);
  }
}
int main() {
  _w = scanf("%d", &n);
  G::init();
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    _w = scanf("%d%d", &u, &v);
    G::link(u, v);
  }
  HLD::init();
  prelude();
  for (int i = 1; i <= n; ++i) {
    int a;
    _w = scanf("%d", &a);
    for (int j = 0; prm[j] * prm[j] <= a; ++j) {
      int x = prm[j], cnt = 0;
      while (a % x == 0) {
        fac[x].push_back(pair<int, int>(++cnt, i));
        a /= x;
      }
    }
    if (a != 1) fac[a].push_back(pair<int, int>(1, i));
  }
  _w = scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    _w = scanf("%d%d", qu + i, qv + i);
    int x;
    _w = scanf("%d", &x);
    for (int j = 0; prm[j] * prm[j] <= x; ++j) {
      int y = prm[j], cnt = 0;
      while (x % y == 0) ++cnt, x /= y;
      if (cnt) qry[y].push_back(pair<int, int>(cnt, i));
    }
    if (x != 1) qry[x].push_back(pair<int, int>(1, i));
    ans[i] = 1;
  }
  solve();
  for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
  return 0;
}