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;
const int MAXM = 1e7;
const int LOG = 18;
const int MOD = 1e9 + 7;
struct Data {
  int id, p, cnt;
  bool end;
  Data(int id, int p, int cnt, bool end) : id(id), p(p), cnt(cnt), end(end){};
};
int lpf[MAXM + 1];
int pa[MAXN + 1][LOG + 1];
int a[MAXN + 1];
int lev[MAXN + 1];
int ans[MAXN + 1];
int freq[MAXM + 1];
vector<int> g[MAXN + 1];
vector<Data> partial[MAXN + 1];
map<int, int> query[MAXN + 1];
int n, q;
int u, v, x;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
}
void sieve() {
  for (int i = 2; i <= MAXM; i++) {
    if (!lpf[i])
      for (int j = i; j <= MAXM; j += i) lpf[j] = i;
  }
}
void dfs(int u, int p) {
  lev[u] = 1 + lev[p];
  pa[u][0] = p;
  for (int i = 1; i <= LOG; i++) {
    pa[u][i] = pa[pa[u][i - 1]][i - 1];
  }
  for (auto v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
  }
}
int mult(int a, int b) { return (1LL * a * b) % MOD; }
int modpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = mult(ans, x);
    x = mult(x, x);
    y >>= 1;
  }
  return ans;
}
int LCA(int u, int v) {
  if (lev[v] > lev[u]) swap(u, v);
  for (int i = LOG; i >= 0; i--) {
    if (lev[u] - (1 << i) >= lev[v]) u = pa[u][i];
  }
  if (u == v) return u;
  for (int i = LOG; i >= 0; i--) {
    if (pa[u][i] != pa[v][i]) {
      u = pa[u][i];
      v = pa[v][i];
    }
  }
  return pa[u][0];
}
vector<pair<int, int> > find(int x) {
  vector<pair<int, int> > res;
  while (x > 1) {
    int p = lpf[x], cnt = 0;
    while (!(x % p)) x /= p, cnt++;
    res.push_back(make_pair(p, cnt));
  }
  return res;
}
void update(int x, int add) {
  vector<pair<int, int> > f = find(x);
  for (auto it : f) {
    int curr = it.first;
    for (int i = 1; i <= it.second; i++) {
      freq[curr] += add;
      curr *= it.first;
    }
  }
}
void solve(int u, int p) {
  update(a[u], 1);
  for (auto o : partial[u]) {
    int curr = o.p;
    for (int i = 1; i <= o.cnt; i++) {
      if (o.end)
        query[o.id][o.p] += freq[curr];
      else
        query[o.id][o.p] -= freq[curr];
      curr *= o.p;
    }
  }
  for (auto v : g[u]) {
    if (v == p) continue;
    solve(v, u);
  }
  update(a[u], -1);
}
int main() {
  fast_io();
  sieve();
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  dfs(1, 1);
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> u >> v >> x;
    vector<pair<int, int> > f = find(x);
    int lca = LCA(u, v);
    for (auto it : f) {
      partial[u].push_back(Data(i, it.first, it.second, 1));
      partial[v].push_back(Data(i, it.first, it.second, 1));
      partial[lca].push_back(Data(i, it.first, it.second, 0));
      if (lca > 1)
        partial[pa[lca][0]].push_back(Data(i, it.first, it.second, 0));
    }
  }
  solve(1, 1);
  for (int i = 1; i <= q; i++) {
    ans[i] = 1;
    for (auto it : query[i]) ans[i] = mult(ans[i], modpow(it.first, it.second));
    cout << ans[i] << '\n';
  }
  return 0;
}