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>
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
    ;
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
int n, q, a[100005];
int ans[100005];
inline int qpow(int x, int k) {
  int ans = 1;
  for (; k; k >>= 1, x = 1ll * x * x % 1000000007)
    if (k & 1) ans = 1ll * ans * x % 1000000007;
  return ans;
}
std::vector<std::pair<int, std::pair<int, int>>> query[100005];
int Min[10000005], pri[10000005 / 10], tp;
bool vis[10000005];
void euler(int mx) {
  for (int i = 2; i <= mx; i++) {
    if (!vis[i]) pri[++tp] = i, Min[i] = tp;
    for (int j = 1; j <= tp && i * pri[j] <= mx; j++) {
      Min[i * pri[j]] = j;
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
int cnt[10000005 / 10][31];
int f[100005][20], dep[100005];
std::vector<int> G[100005];
void dfs(int u, int fa) {
  f[u][0] = fa;
  dep[u] = dep[fa] + 1;
  for (int i = 1; i <= 19; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  for (auto i : G[u])
    if (i != fa) {
      dfs(i, u);
    }
}
inline int lca(int u, int v) {
  if (dep[u] < dep[v]) std::swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (dep[f[u][i]] >= dep[v]) {
      u = f[u][i];
    }
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  return f[u][0];
}
std::vector<std::pair<int, int>> div(int x) {
  std::vector<std::pair<int, int>> ans;
  while (x > 1) {
    int t = Min[x], c = 0;
    while (x % pri[t] == 0) x /= pri[t], c++;
    ans.push_back(std::make_pair(t, c));
  }
  return ans;
}
void solve(int u, int fa) {
  std::vector<std::pair<int, int>> now = div(a[u]);
  for (auto i : now) {
    for (int j = 1; j <= i.second; j++) {
      cnt[i.first][j]++;
    }
  }
  for (auto i : query[u]) {
    int w = i.first;
    std::vector<std::pair<int, int>> t = div(w);
    int R = 1;
    for (auto p : t) {
      int C = 0;
      for (int j = 1; j <= p.second; j++) {
        R = 1ll * R * qpow(pri[p.first], cnt[p.first][j]) % 1000000007;
        C += cnt[p.first][j];
      }
    }
    if (i.second.second == -1) {
      ans[i.second.first] =
          1ll * ans[i.second.first] * qpow(R, 1000000007 - 2) % 1000000007;
    } else {
      ans[i.second.first] = 1ll * ans[i.second.first] * R % 1000000007;
    }
  }
  for (auto i : G[u])
    if (i != fa) {
      solve(i, u);
    }
  for (auto i : now) {
    for (int j = 1; j <= i.second; j++) {
      cnt[i.first][j]--;
    }
  }
}
int main() {
  n = rd();
  for (int i = 2; i <= n; i++) {
    int x = rd(), y = rd();
    G[x].push_back(y), G[y].push_back(x);
  }
  int MAX = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = rd();
    MAX = std::max(MAX, a[i]);
  }
  euler(10000000);
  dfs(1, 0);
  q = rd();
  for (int i = 1; i <= q; i++) {
    int u = rd(), v = rd(), w = rd();
    int l = lca(u, v);
    ans[i] = 1;
    query[u].push_back(std::make_pair(w, std::make_pair(i, 1)));
    query[v].push_back(std::make_pair(w, std::make_pair(i, 1)));
    query[l].push_back(std::make_pair(w, std::make_pair(i, -1)));
    if (l != 1)
      query[f[l][0]].push_back(std::make_pair(w, std::make_pair(i, -1)));
  }
  solve(1, 0);
  for (int i = 1; i <= q; i++) {
    wrt(ans[i], '\n');
  }
}