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
#include <bits/stdc++.h>
using namespace std;
template <int mod>
struct modulo {
  int w;
  template <typename type>
  operator type() const {
    return static_cast<type>(w);
  }
  modulo() {}
  modulo(int w) {
    this->w = w;
    fix();
  }
  void inline fix() {
    if (w >= mod || w < -mod) w %= mod;
    if (w < 0) w += mod;
  }
  inline modulo operator-() const { return mod - w; }
  inline modulo &operator+=(const modulo &b) {
    if ((w += b.w) >= mod) w -= mod;
    return *this;
  }
  inline modulo &operator-=(const modulo &b) {
    if ((w -= b.w) < 0) w += mod;
    return *this;
  }
  inline modulo &operator*=(const modulo &b) {
    w = (unsigned long long)w * b.w % mod;
    return *this;
  }
  inline modulo &operator/=(const modulo &b) { return *this *= inv(b); }
  friend modulo operator+(const modulo &a, const modulo &b) {
    return modulo(a) += b;
  }
  template <typename type>
  friend modulo operator+(const modulo &a, const type &b) {
    return modulo(a) += b;
  }
  template <typename type>
  friend modulo operator+(const type &a, const modulo &b) {
    return modulo(a) += b;
  }
  friend modulo operator-(const modulo &a, const modulo &b) {
    return modulo(a) -= b;
  }
  template <typename type>
  friend modulo operator-(const modulo &a, const type &b) {
    return modulo(a) -= b;
  }
  template <typename type>
  friend modulo operator-(const type &a, const modulo &b) {
    return modulo(a) -= b;
  }
  friend modulo operator*(const modulo &a, const modulo &b) {
    return modulo(a) *= b;
  }
  template <typename type>
  friend modulo operator*(const modulo &a, const type &b) {
    return modulo(a) *= b;
  }
  template <typename type>
  friend modulo operator*(const type &a, const modulo &b) {
    return modulo(a) *= b;
  }
  friend modulo operator/(const modulo &a, const modulo &b) {
    return modulo(a) /= b;
  }
  template <typename type>
  friend modulo operator/(const modulo &a, const type &b) {
    return modulo(a) /= b;
  }
  template <typename type>
  friend modulo operator/(const type &a, const modulo &b) {
    return modulo(a) /= b;
  }
  friend istream &operator>>(istream &in, modulo &a) { return in >> a.w; }
  friend ostream &operator<<(ostream &out, const modulo &a) {
    return out << a.w;
  }
  friend inline modulo inv(const modulo &w) {
    int a = w, m = mod, u = 0, v = 1, t;
    for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v))
      ;
    return u;
  }
  friend inline modulo pow(const modulo &w, int p) {
    if (!w) return 0;
    modulo a = w, r = 1;
    for (; p > 0; a *= a, p >>= 1)
      if (p & 1) r *= a;
    return r;
  }
};
const int mod = int(1e9) + 7;
const int nsz = 1e5, sqrt_asz = 3162;
int n, q, a[nsz + 5];
int rt = 1, pr[nsz + 5], dep[nsz + 5], siz[nsz + 5], hs[nsz + 5], top[nsz + 5],
    id[nsz + 5], fm[nsz + 5];
modulo<mod> ans[nsz + 5];
vector<int> p, dd, d[nsz + 5], e[nsz + 5];
vector<vector<pair<int, int> > > d1, q1;
struct fenwick_tree {
  int t, tm[nsz + 5], tr[nsz + 5];
  void inline clear() { ++t; }
  void inline chg(int u) {
    if (tm[u] != t) tm[u] = t, tr[u] = 0;
  }
  void inline upd(int l, int r, int w) { upd(l, +w), upd(r + 1, -w); }
  void inline upd(int u, int w) {
    for (; u <= n; u += u & -u) chg(u), tr[u] += w;
  }
  int inline qry(int u) {
    int res = 0;
    for (; u > 0; u -= u & -u) chg(u), res += tr[u];
    return res;
  }
};
fenwick_tree tr;
struct graph {
  int sz, hd[nsz + 5];
  struct edge {
    int nxt, to;
    edge() {}
    edge(int nxt, int to) : nxt(nxt), to(to) {}
  } e[2 * nsz + 5];
  inline edge &operator[](int id) { return e[id]; }
  void inline link(int u, int v) {
    e[++sz] = edge(hd[u], v), hd[u] = sz;
    e[++sz] = edge(hd[v], u), hd[v] = sz;
  }
};
graph g;
struct query {
  int u, v, w;
  query() {}
  query(int u, int v, int w) : u(u), v(v), w(w) {}
};
query qy[nsz + 5];
void inline prime_init(int n = sqrt_asz) {
  static bool np[sqrt_asz + 5];
  for (int a = 2; a <= n; ++a)
    if (!np[a]) {
      p.push_back(a);
      for (int b = 2 * a; b <= n; b += a) np[b] = 1;
    }
}
void inline factorize(int a, vector<int> &d, vector<int> &e) {
  int cur = a;
  for (int i = 0; i < p.size(); ++i) {
    int p = ::p[i];
    if (p * p > a || cur == 1) break;
    if (cur % p) continue;
    int cnt = 0;
    for (; cur % p == 0; cur /= p) ++cnt;
    d.push_back(p), e.push_back(cnt);
  }
  if (cur > 1) d.push_back(cur), e.push_back(1);
}
int inline id_of(vector<int> &dat, int w) {
  vector<int>::iterator it = lower_bound(dat.begin(), dat.end(), w);
  return it == dat.end() || *it != w ? -1 : it - dat.begin();
}
void dfs1(int u = rt) {
  siz[u] = 1;
  for (int i = g.hd[u]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == pr[u]) continue;
    pr[v] = u, dep[v] = dep[u] + 1;
    dfs1(v);
    siz[u] += siz[v];
    if (siz[hs[u]] < siz[v]) hs[u] = v;
  }
}
void dfs2(int u = rt, int tp = rt) {
  static int t = 0;
  id[u] = ++t, fm[t] = u, top[u] = tp;
  if (!hs[u]) return;
  dfs2(hs[u], tp);
  for (int i = g.hd[u]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == pr[u] || v == hs[u]) continue;
    dfs2(v, v);
  }
}
int inline lca(int u, int v) {
  for (; top[u] != top[v]; v = pr[top[v]]) {
    if (dep[top[u]] > dep[top[v]]) swap(u, v);
  }
  if (dep[u] > dep[v]) swap(u, v);
  return u;
}
void inline upd_subtree(int u, int w) { tr.upd(id[u], id[u] + siz[u] - 1, w); }
int inline qry_route(int u) { return tr.qry(id[u]); }
void inline init() {
  prime_init();
  for (int i = 1; i <= n; ++i) {
    factorize(a[i], d[i], e[i]);
    for (int j = 0; j < d[i].size(); ++j) dd.push_back(d[i][j]);
  }
  sort(dd.begin(), dd.end()), dd.erase(unique(dd.begin(), dd.end()), dd.end());
  dfs1(), dfs2();
  d1.resize(dd.size()), q1.resize(dd.size());
  for (int t = 1; t <= n; ++t) {
    int u = fm[t];
    for (int i = 0; i < d[u].size(); ++i) {
      int p = d[u][i], pid = id_of(dd, p);
      d1[pid].push_back(make_pair(e[u][i], u));
    }
  }
  for (int id = 1; id <= q; ++id) {
    int u = qy[id].u, v = qy[id].v, w = qy[id].w;
    vector<int> d, e;
    factorize(w, d, e);
    for (int i = 0; i < d.size(); ++i) {
      int p = d[i], pid = id_of(dd, p);
      if (pid == -1) continue;
      q1[pid].push_back(make_pair(e[i], id));
    }
  }
  for (int i = 0; i < dd.size(); ++i)
    sort(d1[i].begin(), d1[i].end()), reverse(d1[i].begin(), d1[i].end()),
        sort(q1[i].begin(), q1[i].end());
  for (int i = 1; i <= q; ++i) ans[i] = 1;
}
void inline solve() {
  for (int i = 0; i < dd.size(); ++i) {
    int p = dd[i], cur = 0;
    for (int j = 0; j < q1[i].size(); ++j) {
      int k = q1[i][j].first, id = q1[i][j].second;
      int u = qy[id].u, v = qy[id].v, pp = lca(u, v), r;
      if (cur < k) {
        for (int j = 0; j < d1[i].size(); ++j) {
          int u = d1[i][j].second, ck = d1[i][j].first;
          if (ck <= cur) break;
          upd_subtree(u, min(k - cur, ck - cur));
        }
        cur = k;
      }
      r = qry_route(u) + qry_route(v) - qry_route(pp) - qry_route(pr[pp]);
      ans[id] *= pow(modulo<mod>(p), r);
    }
    tr.clear();
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g.link(u, v);
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    qy[i] = query(u, v, w);
  }
  init();
  solve();
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i].w);
}
