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 = 2e5 + 100;
const int lg = 19;
const int maxm = 1e7 + 100;
const int mod = 1e9 + 7;
const int inf = 1e9;
int n, m, d[maxn], a[maxn], par[lg][maxn], p[maxm], cnt[maxm];
long long ans[maxn];
vector<int> g[maxn];
vector<pair<int, int> > q[maxn], vec[maxn];
void dfs(int v) {
  for (int u : g[v]) {
    if (u == par[0][v]) continue;
    d[u] = d[v] + 1;
    par[0][u] = v;
    for (int i = 1; i < lg; i++) {
      par[i][u] = par[i - 1][par[i - 1][u]];
    }
    dfs(u);
  }
  return;
}
int lca(int v, int u) {
  if (d[v] < d[u]) swap(v, u);
  int h = d[v] - d[u];
  for (int i = 0; i < lg; i++) {
    if ((h >> i) & 1) v = par[i][v];
  }
  for (int i = lg; i--;) {
    if (d[v] >= (1 << i) && par[i][v] != par[i][u]) {
      v = par[i][v];
      u = par[i][u];
    }
  }
  if (v != u) v = par[0][v];
  return v;
}
long long pw(int pa, int push_back) {
  if (push_back == 0) return 1;
  long long pc = pw(pa, push_back >> 1);
  pc = (pc * pc) % mod;
  if (push_back & 1) pc = (pc * pa) % mod;
  return pc;
}
void solve(int v) {
  int x = a[v];
  while (x != 1) {
    int y = p[x];
    int z = 1;
    while (x % y == 0) {
      x /= y;
      z *= y;
      cnt[z]++;
    }
  }
  for (pair<int, int> i : q[v]) {
    int e = 1;
    for (pair<int, int> j : vec[i.first]) {
      int z = 1;
      int c = 0;
      for (int k = 1; k <= j.second; k++) {
        z *= j.first;
        c += cnt[z];
      }
      e = (e * pw(j.first, c)) % mod;
    }
    if (i.second == 1) {
      ans[i.first] = (ans[i.first] * e) % mod;
    } else {
      ans[i.first] = (ans[i.first] * pw(e, mod - 2)) % mod;
    }
  }
  for (int u : g[v]) {
    if (u != par[0][v]) solve(u);
  }
  x = a[v];
  while (x != 1) {
    int y = p[x];
    int z = 1;
    while (x % y == 0) {
      x /= y;
      z *= y;
      cnt[z]--;
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = 2; i < maxm; i++) {
    if (p[i]) continue;
    p[i] = i;
    if (i > 10000) continue;
    for (int j = i * i; j < maxm; j += i) {
      p[j] = i;
    }
  }
  cin >> n;
  for (int i = 1; i < n; i++) {
    int v, u;
    cin >> v >> u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  dfs(1);
  cin >> m;
  for (int i = 0; i < m; i++) {
    ans[i] = 1;
    int v, u, x;
    cin >> v >> u >> x;
    int l = lca(v, u);
    q[v].push_back(make_pair(i, 1));
    q[u].push_back(make_pair(i, 1));
    q[l].push_back(make_pair(i, -1));
    q[par[0][l]].push_back(make_pair(i, -1));
    while (x != 1) {
      int y = p[x];
      int z = 0;
      while (x % y == 0) {
        x /= y;
        z++;
      }
      if (z) {
        vec[i].push_back(make_pair(y, z));
      }
    }
  }
  solve(1);
  for (int i = 0; i < m; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}