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::vector;
inline int read() {
  int out(0), c(getchar());
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c <= '9' && c >= '0'; c = getchar())
    out = (out << 3) + (out << 1) + (c ^ 48);
  return out;
}
const int MAXN = 1e5 + 100, MAXR = 1e7 + 100, R = 1e7;
const int pm = 1e9 + 7;
int N, Q;
int a[MAXN];
int ans[MAXN];
int pri[664579 + 100], pn;
vector<int> to[MAXN];
int vec[664579 + 100][25];
int mi[18][MAXN << 1], _log[MAXN << 1];
int fs[MAXN], dep[MAXN], cnt;
struct QR {
  int i, w;
  bool inv;
};
vector<QR> q[MAXN];
void pre() {
  static bool inp[MAXR];
  for (int i = 2; i <= R; ++i) {
    if (!inp[i]) pri[++pn] = i;
    for (int j = 1; j <= pn && i * pri[j] <= R; ++j) {
      inp[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
int cal(const int a, const int b) { return dep[a] < dep[b] ? a : b; }
void dfs0(const int x, const int fa) {
  fs[x] = ++cnt;
  mi[0][cnt] = x;
  for (int tt : to[x]) {
    if (tt != fa) {
      dep[tt] = dep[x] + 1;
      dfs0(tt, x);
      mi[0][++cnt] = x;
    }
  }
}
int gt_lca(int x, int y) {
  x = fs[x], y = fs[y];
  if (x > y) std::swap(x, y);
  const int k = _log[y - x + 1];
  return cal(mi[k][x], mi[k][y - (1 << k) + 1]);
}
int gcd(const int a, const int b) { return b ? gcd(b, a % b) : a; }
int qpow(int a, int b) {
  int out = 1;
  for (; b; b >>= 1, a = (long long)a * a % pm)
    if (b & 1) out = (long long)out * a % pm;
  return out;
}
void dfs(const int x, const int fa) {
  int v = a[x];
  for (int i = 1; i <= pn && pri[i] * pri[i] <= v; ++i) {
    if (v % pri[i] == 0) {
      int cnt = 0;
      while (v % pri[i] == 0) v /= pri[i], ++cnt;
      ++vec[i][cnt];
    }
  }
  if (v != 1) ++vec[std::lower_bound(pri + 1, pri + pn + 1, v) - pri][1];
  for (QR qr : q[x]) {
    v = qr.w;
    int tmp = 1;
    for (int i = 1; i <= pn && pri[i] * pri[i] <= v; ++i) {
      if (v % pri[i] == 0) {
        int cnt = 0;
        while (v % pri[i] == 0) v /= pri[i], ++cnt;
        int p = pri[i];
        for (int j = 1; j < cnt; ++j, p = (long long)p * pri[i] % pm)
          tmp = (long long)tmp * qpow(p, vec[i][j]) % pm;
        for (int j = cnt; j <= 24; ++j)
          tmp = (long long)tmp * qpow(p, vec[i][j]) % pm;
      }
    }
    if (v != 1) {
      const int pi = std::lower_bound(pri + 1, pri + pn + 1, v) - pri;
      for (int j = 1; j <= 24; ++j)
        tmp = (long long)tmp * qpow(v, vec[pi][j]) % pm;
    }
    ans[qr.i] = (long long)ans[qr.i] *
                (qr.inv ? qpow((long long)tmp * tmp % pm, pm - 2) : tmp) % pm;
  }
  v = a[x];
  for (int tt : to[x])
    if (tt != fa) dfs(tt, x);
  for (int i = 1; i <= pn && pri[i] * pri[i] <= v; ++i) {
    if (v % pri[i] == 0) {
      int cnt = 0;
      while (v % pri[i] == 0) v /= pri[i], ++cnt;
      --vec[i][cnt];
    }
  }
  if (v != 1) --vec[std::lower_bound(pri + 1, pri + pn + 1, v) - pri][1];
}
int main() {
  pre();
  N = read();
  for (int i = 1, x, y; i < N; ++i) {
    x = read(), y = read();
    to[x].push_back(y);
    to[y].push_back(x);
  }
  for (int i = 1; i <= N; ++i) a[i] = read();
  dfs0(1, 0);
  for (int i = 1; i <= 17; ++i)
    for (int s = (1 << i); s < (1 << (i + 1)) && s <= cnt; ++s) _log[s] = i;
  for (int i = 1; i <= 17; ++i)
    for (int j = 1; j <= cnt; ++j)
      mi[i][j] = cal(
          mi[i - 1][j],
          mi[i - 1]
            [((cnt) < (j + (1 << (i - 1))) ? (cnt) : (j + (1 << (i - 1))))]);
  Q = read();
  for (int i = 1, x, y, w; i <= Q; ++i) {
    x = read(), y = read(), w = read();
    const int p = gt_lca(x, y);
    ans[i] = gcd(w, a[p]);
    q[x].push_back({i, w, 0});
    q[y].push_back({i, w, 0});
    q[p].push_back({i, w, 1});
  }
  dfs(1, 0);
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}