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;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
const int INF = 2139062143;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 1e5 + 7;
const int P = 1e6 + 7;
const int M = 1e7 + 1;
const int mod = 1e9 + 7;
const int LOG = 20 + 5;
int n, m, E, tot, a[N], w[N], ans[N], dep[N], head[N], prime[P], f[N][LOG],
    cnt[P][LOG];
vector<int> q[N];
bool vis[M];
struct EDGE {
  int to, nxt;
} edge[N << 1];
inline void addedge(int u, int v) {
  edge[++E].to = v;
  edge[E].nxt = head[u];
  head[u] = E;
}
inline void lca_dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  f[u][0] = fa;
  for (int i = 1; i <= 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fa) continue;
    lca_dfs(v, u);
  }
}
inline int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 20; i >= 0; i--) {
    if (dep[f[u][i]] >= dep[v]) u = f[u][i];
    if (u == v) return u;
  }
  if (u == v) return u;
  for (int i = 20; i >= 0; i--) {
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  }
  return f[u][0];
}
inline void init(int NN) {
  for (int i = 2; i <= NN; i++) {
    if (!vis[i]) {
      prime[++tot] = i;
    }
    for (int j = 1; j <= tot && prime[j] * i <= NN; j++) {
      vis[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
inline int qpow(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = 1ll * ret * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return ret % mod;
}
inline void add(int val, int opt) {
  for (int i = 1; 1ll * prime[i] * prime[i] <= val && i <= tot; i++) {
    if (val % prime[i]) continue;
    int p = 0;
    while (val % prime[i] == 0) {
      val /= prime[i];
      p++;
    }
    cnt[i][p] += opt;
  }
  if (val != 1) {
    int pos = lower_bound(prime + 1, prime + tot + 1, val) - prime;
    cnt[pos][1] += opt;
  }
}
inline int gcd(int x, int y) {
  if (x < y) swap(x, y);
  return y == 0 ? x : gcd(y, x % y);
}
inline int sqr(int x) { return 1ll * x * x % mod; }
inline int query(int val) {
  int ans = 1;
  for (int i = 1; 1ll * prime[i] * prime[i] <= val && i <= tot; i++) {
    if (val % prime[i]) continue;
    int p = 0;
    while (val % prime[i] == 0) {
      val /= prime[i];
      p++;
    }
    int s = 0;
    for (int j = 1; j <= p; j++) s += cnt[i][j] * j;
    for (int j = p + 1; j < LOG; j++) s += cnt[i][j] * p;
    ans = 1ll * ans * qpow(prime[i], s) % mod;
  }
  if (val != 1) {
    int pos = lower_bound(prime + 1, prime + tot + 1, val) - prime;
    int s = 0;
    for (int j = 1; j < LOG; j++) s += cnt[pos][j];
    ans = 1ll * ans * qpow(val, s) % mod;
  }
  return ans;
}
inline void dfs(int u, int f) {
  add(a[u], 1);
  for (int i = 0, sz = q[u].size(); i < sz; i++) {
    int id = q[u][i];
    int x = query(w[abs(id)]);
    if (id > 0) ans[id] = 1ll * ans[id] % mod * x % mod;
    if (id < 0)
      ans[-id] = 1ll * ans[-id] % mod * qpow(1ll * x * x % mod, mod - 2) % mod *
                 gcd(w[-id], a[u]) % mod;
  }
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == f) continue;
    dfs(v, u);
  }
  add(a[u], -1);
}
int main() {
  read(n);
  init(1e7);
  for (int i = 1, u, v; i < n; i++) {
    read(u);
    read(v);
    addedge(u, v);
    addedge(v, u);
  }
  lca_dfs(1, 0);
  for (int i = 1; i <= n; i++) read(a[i]);
  read(m);
  for (int i = 1, x, y, z; i <= m; i++) {
    read(x);
    read(y);
    read(z);
    int LCA = lca(x, y);
    w[i] = z;
    ans[i] = 1;
    q[LCA].push_back(-i);
    q[x].push_back(i);
    q[y].push_back(i);
  }
  dfs(1, 0);
  for (int i = 1; i <= m; i++) printf("%d\n", (ans[i] % mod + mod) % mod);
  return 0;
}