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;
const int N = 2e5 + 10;
int n, q, head[N], nxt[N], w[N];
void add(int f, int t) {
  static int cnt = 0;
  w[++cnt] = t;
  nxt[cnt] = head[f];
  head[f] = cnt;
}
struct bit {
  int a[N];
  void add(int p, int v) {
    for (; p <= n; p += p & -p) a[p] += v;
  }
  void add(int l, int r, int v) {
    add(l, v);
    add(r + 1, -v);
  }
  int query(int x) {
    int ans = 0;
    for (; x; x -= x & -x) ans += a[x];
    return ans;
  }
} T;
int dfn[N], size[N], fa[N], link[N], big[N];
void dfs(int x) {
  size[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    int v = w[i];
    if (size[v]) continue;
    fa[v] = x;
    dfs(v);
    size[x] += size[v];
    if (size[v] > size[big[x]]) big[x] = v;
  }
}
void divide(int x) {
  static int cnt = 0;
  dfn[x] = ++cnt;
  link[x] = (dfn[x] == dfn[fa[x]] + 1 ? link[fa[x]] : x);
  if (!big[x]) return;
  divide(big[x]);
  for (int i = head[x]; i; i = nxt[i])
    if (w[i] != fa[x] && w[i] != big[x]) divide(w[i]);
}
int lca(int x, int y) {
  for (; link[x] != link[y]; x = fa[link[x]])
    if (dfn[link[x]] < dfn[link[y]]) swap(x, y);
  return dfn[x] < dfn[y] ? x : y;
}
const int V = 1e7 + 10, M = 1e6 + 10;
bitset<V> isp;
int prime[M], id[V], pcnt;
void init() {
  int n = 1e7;
  for (int i = 2; i <= n; i++) {
    if (!isp[i]) prime[++pcnt] = i, id[i] = pcnt;
    for (int j = 1; j <= pcnt && i * prime[j] <= n; j++) {
      isp[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
struct opt {
  int id, u, v, T;
};
vector<opt> Q[M];
const int p = 1e9 + 7;
int mul(int x, int y) { return (long long)x * y % p; }
int power(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = mul(x, x))
    if (y & 1) ans = mul(ans, x);
  return ans;
}
int ans[N];
void change(int x, int val) {
  for (int i = 1; prime[i] * prime[i] <= val; i++)
    if (val % prime[i] == 0) {
      int c = 0;
      while (val % prime[i] == 0)
        Q[i].push_back((opt){0, x, 1, ++c}), val /= prime[i];
    }
  if (val > 1) Q[id[val]].push_back((opt){0, x, 1, 1});
}
void query(int u, int v, int val, int ID) {
  for (int i = 1; prime[i] * prime[i] <= val; i++)
    if (val % prime[i] == 0) {
      int c = 0;
      while (val % prime[i] == 0) val /= prime[i], c++;
      Q[i].push_back((opt){ID, u, v, c});
    }
  if (val > 1) Q[id[val]].push_back((opt){ID, u, v, 1});
}
bool cmp(const opt &a, const opt &b) {
  return a.T != b.T ? a.T < b.T : a.id < b.id;
}
void work(int pid) {
  vector<opt> &q = Q[pid];
  sort(q.begin(), q.end(), cmp);
  for (opt now : q) {
    int id = now.id, u = now.u, v = now.v;
    if (id == 0)
      T.add(dfn[u], dfn[u] + size[u] - 1, 1);
    else {
      int LCA = lca(u, v);
      int pw = T.query(dfn[u]) + T.query(dfn[v]) - T.query(dfn[LCA]) -
               T.query(dfn[fa[LCA]]);
      ans[id] = mul(ans[id], power(prime[pid], pw));
    }
  }
  for (opt now : q) {
    int id = now.id, u = now.u, v = now.v;
    if (id == 0) T.add(dfn[u], dfn[u] + size[u] - 1, -1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  dfs(1);
  divide(1);
  init();
  for (int i = 1, a; i <= n; i++) scanf("%d", &a), change(i, a);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int u, v, x;
    scanf("%d%d%d", &u, &v, &x);
    query(u, v, x, i);
    ans[i] = 1;
  }
  for (int i = 1; i <= pcnt; i++) work(i);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}