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 maxn = 1e5, MaxStep = 17;
const int maxA = 1e7;
const int md = 1e9 + 7;
inline long long PowMod(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = r * a % md;
    a = a * a % md, b >>= 1;
  }
  return r;
}
long long Gcd(long long a, long long b) { return b ? Gcd(b, a % b) : a; }
vector<pair<int, int> > deco[maxn * 2 + 5];
void Deco(int id, int x) {
  int a = x;
  for (int i = 2; i * i <= a; ++i) {
    int c = 0;
    while (a % i == 0) a /= i, ++c;
    if (c) deco[id].push_back(make_pair(i, c));
  }
  if (a) deco[id].push_back(make_pair(a, 1));
}
int n, m, ai[maxn + 5];
int st[maxn + 5][MaxStep + 2], dep[maxn + 5];
vector<int> G[maxn + 5];
vector<pair<int, int> > add[maxn + 5], sub[maxn + 5];
long long ans[maxn + 5];
int cnt[maxA + 5];
void dfs(int x, int p, int d) {
  st[x][0] = p, dep[x] = d;
  for (int i = 0; st[x][i]; ++i) st[x][i + 1] = st[st[x][i]][i];
  for (auto it : G[x])
    if (it != p) dfs(it, x, d + 1);
}
int LCA(int u, int v) {
  if (u == v) return u;
  if (dep[u] < dep[v]) swap(u, v);
  int del = dep[u] - dep[v];
  for (int i = MaxStep; i >= 0; --i)
    if (del >> i & 1) u = st[u][i];
  if (u == v) return u;
  for (int i = MaxStep; i >= 0; --i) {
    if (st[u][i] != st[v][i]) u = st[u][i], v = st[v][i];
  }
  return st[u][0];
}
void dfs2(int x, int p) {
  for (auto it : deco[x]) {
    for (int i = 1, a = it.first; i <= it.second; ++i, a *= it.first) ++cnt[a];
  }
  for (auto it : add[x]) {
    for (auto it2 : deco[it.first + n]) {
      int c = 0;
      for (int i = 1, a = it2.first; i <= it2.second; ++i, a *= it2.first)
        c += cnt[a];
      ans[it.first] = ans[it.first] * PowMod(it2.first, c) % md;
    }
  }
  for (auto it : sub[x]) {
    long long tmp = 1;
    for (auto it2 : deco[it.first + n]) {
      int c = 0;
      for (int i = 1, a = it2.first; i <= it2.second; ++i, a *= it2.first)
        c += cnt[a];
      tmp = tmp * PowMod(it2.first, c) % md;
    }
    ans[it.first] =
        ans[it.first] * PowMod(tmp, md - 3) % md * Gcd(it.second, ai[x]) % md;
  }
  for (auto it : G[x]) {
    if (it != p) dfs2(it, x);
  }
  for (auto it : deco[x]) {
    for (int i = 1, a = it.first; i <= it.second; ++i, a *= it.first) --cnt[a];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v), G[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) scanf("%d", ai + i), Deco(i, ai[i]);
  dfs(1, 0, 0);
  scanf("%d", &m);
  for (int i = 1, u, v, w; i <= m; ++i) {
    scanf("%d%d%d", &u, &v, &w), Deco(n + i, w);
    int lca = LCA(u, v);
    add[u].push_back(make_pair(i, w));
    add[v].push_back(make_pair(i, w));
    sub[lca].push_back(make_pair(i, w));
    ans[i] = 1;
  }
  dfs2(1, 0);
  for (int i = 1; i <= m; ++i) printf("%lld\n", ans[i]);
  return 0;
}