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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
const int N = 3e5 + 100, OO = 1e9 + 7, K = 1e7 + 4, T = 22, M = 1e9 + 7,
          P = 6151, SQ = 1300, lg = 22;
int pr[N][lg + 5], F[K + 5], cnt[K + 5], h[N], ans[N], num[N], nxt = 0, a[N];
bool mark[N];
vector<int> v[N];
vector<pair<pair<int, int>, pair<int, int> > > qu[N];
void dfs(int x, int y) {
  pr[x][0] = y;
  for (int i = 1; i <= lg; i++) pr[x][i] = pr[pr[x][i - 1]][i - 1];
  h[x] = h[y] + 1;
  for (auto u : v[x])
    if (u != y) dfs(u, x);
}
int Lca(int x, int y) {
  if (h[x] < h[y]) swap(x, y);
  for (int i = lg; i >= 0; i--)
    if (h[pr[x][i]] >= h[y]) x = pr[x][i];
  if (x == y) return x;
  for (int i = lg; i >= 0; i--)
    if (pr[x][i] != pr[y][i]) x = pr[x][i], y = pr[y][i];
  return pr[x][0];
}
void get(int x) {
  nxt = 0;
  while (x > 1) num[nxt++] = F[x], x /= F[x];
  num[nxt] = 0;
}
int pw(int x, int y) {
  int ct = 1;
  y %= M;
  while (y) {
    if (y & 1) ct = 1ll * ct * x % M;
    x = 1ll * x * x % M;
    y >>= 1;
  }
  return ct;
}
inline int pwt(int tp, int x, int y) {
  int ct = pw(x, y);
  if (tp == 1)
    return ct;
  else
    return pw(ct, M - 2);
}
void dfs_get(int x, int y) {
  get(a[x]);
  for (int i = 0; i < nxt; i++) {
    int j = i, cer = num[i];
    while (num[j + 1] == num[j]) j++, cer *= num[i];
    cnt[cer]++;
    i = j;
  }
  for (auto u : qu[x]) {
    int tp = u.first.first, p = u.first.second, nw = u.second.first,
        id = u.second.second;
    int w = 1, h = 0;
    while (1ll * w * p < K) h++, w *= p;
    int sum = 0;
    for (int i = h; i > nw; i--) sum += cnt[w], w /= p;
    ans[id] = (1ll * ans[id] * pwt(tp, w, sum)) % M;
    for (int i = nw; i >= 0; i--)
      ans[id] = 1ll * ans[id] * pwt(tp, w, cnt[w]) % M, w /= p;
  }
  for (auto u : v[x])
    if (u != y) dfs_get(u, x);
  get(a[x]);
  for (int i = 0; i < nxt; i++) {
    int j = i, cer = num[i];
    while (num[j + 1] == num[j]) j++, cer *= num[i];
    cnt[cer]--;
    i = j;
  }
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 2; i < K; i++) {
    if (F[i]) continue;
    F[i] = i;
    for (long long j = i * i; j < K; j += i)
      if (!F[j]) F[j] = i;
  }
  dfs(1, 0);
  int q;
  cin >> q;
  for (int tp = 1; tp <= q; tp++) {
    int x, y, w;
    cin >> x >> y >> w;
    get(w);
    int z = Lca(x, y);
    ans[tp] = 1;
    for (int i = 0; i < nxt; i++) {
      int j = i;
      while (num[j + 1] == num[j]) j++;
      qu[x].push_back({{+1, num[i]}, {j - i + 1, tp}});
      qu[y].push_back({{+1, num[i]}, {j - i + 1, tp}});
      qu[z].push_back({{-1, num[i]}, {j - i + 1, tp}});
      qu[pr[z][0]].push_back({{-1, num[i]}, {j - i + 1, tp}});
      i = j;
    }
  }
  dfs_get(1, 0);
  for (int tp = 1; tp <= q; tp++) cout << ans[tp] << endl;
  return 0;
}