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 lim = 10000001, mod = 1e9 + 7;
char vaz[lim + 10];
vector<int> primes, v[100010], normm, cnt[2000010];
vector<pair<int, int>> divz[100010], divzq[100010], qry[100010];
int l, first[100010], niv[100010], logg[200010], rmq[200010][20], ans[100010],
    tat[100010];
void ciur() {
  for (int i = 2; i <= lim; i++)
    if (vaz[i] == 0) {
      primes.push_back(i);
      for (long long j = 1LL * i * i; j <= lim; j += i) vaz[j] = 1;
    }
}
int rid_put(int a, int b) {
  int sol = 1;
  for (int i = 1; i <= b; i <<= 1) {
    if (b & i) sol = (1LL * sol * a) % mod;
    a = (1LL * a * a) % mod;
  }
  return sol;
}
void dfs1(int nod, int nivel, int tata) {
  niv[nod] = nivel;
  rmq[++l][0] = nod;
  first[nod] = l;
  tat[nod] = tata;
  for (int i = 0; i < v[nod].size(); i++)
    if (v[nod][i] != tata) {
      dfs1(v[nod][i], nivel + 1, nod);
      rmq[++l][0] = nod;
    }
}
int lca(int a, int b) {
  a = first[a];
  b = first[b];
  if (a > b) swap(a, b);
  int l1 = logg[b - a + 1];
  if (niv[rmq[a][l1]] < niv[rmq[b - (1 << l1) + 1][l1]])
    return rmq[a][l1];
  else
    return rmq[b - (1 << l1) + 1][l1];
}
void dfs2(int nod, int tata) {
  for (int i = 0; i < divz[nod].size(); i++) {
    int poz = lower_bound(normm.begin(), normm.end(), divz[nod][i].first) -
              normm.begin();
    int nr = divz[nod][i].second;
    if (nr + 1 > cnt[poz].size()) cnt[poz].resize(nr + 1);
    cnt[poz][nr]++;
  }
  for (int i = 0; i < qry[nod].size(); i++) {
    int q = qry[nod][i].first;
    for (int j = 0; j < divzq[q].size(); j++) {
      int poz = lower_bound(normm.begin(), normm.end(), divzq[q][j].first) -
                normm.begin();
      int nr = 0;
      for (int k = 1; k < cnt[poz].size(); k++)
        if (divzq[q][j].second >= k)
          nr += k * cnt[poz][k];
        else
          nr += divzq[q][j].second * cnt[poz][k];
      nr = rid_put(divzq[q][j].first, nr);
      if (qry[nod][i].second == -1) nr = rid_put(nr, mod - 2);
      ans[q] = (1LL * ans[q] * nr) % mod;
    }
  }
  for (int i = 0; i < v[nod].size(); i++)
    if (v[nod][i] != tata) dfs2(v[nod][i], nod);
  for (int i = 0; i < divz[nod].size(); i++) {
    int poz = lower_bound(normm.begin(), normm.end(), divz[nod][i].first) -
              normm.begin();
    cnt[poz][divz[nod][i].second]--;
  }
}
int main() {
  int n, x, y, c, q;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  ciur();
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    for (int j = 0; j < primes.size(); j++) {
      if (1LL * primes[j] * primes[j] > x) break;
      if (x % primes[j] != 0) continue;
      int nr = 0;
      while (x % primes[j] == 0) {
        x /= primes[j];
        nr++;
      }
      divz[i].push_back({primes[j], nr});
      normm.push_back(primes[j]);
    }
    if (x > 1) {
      divz[i].push_back({x, 1});
      normm.push_back(x);
    }
  }
  dfs1(1, 0, 0);
  logg[1] = 0;
  for (int i = 2; i <= l; i++) logg[i] = logg[i / 2] + 1;
  for (int i = 1; i <= logg[l]; i++)
    for (int j = 1; j + (1 << i) - 1 <= l; j++)
      if (niv[rmq[j][i - 1]] < niv[rmq[j + (1 << (i - 1))][i - 1]])
        rmq[j][i] = rmq[j][i - 1];
      else
        rmq[j][i] = rmq[j + (1 << (i - 1))][i - 1];
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &x, &y, &c);
    ans[i] = 1;
    int z = lca(x, y);
    qry[x].push_back({i, 1});
    qry[y].push_back({i, 1});
    qry[z].push_back({i, -1});
    qry[tat[z]].push_back({i, -1});
    for (int j = 0; j < primes.size(); j++) {
      if (1LL * primes[j] * primes[j] > c) break;
      if (c % primes[j] != 0) continue;
      int nr = 0;
      while (c % primes[j] == 0) {
        c /= primes[j];
        nr++;
      }
      divzq[i].push_back({primes[j], nr});
      normm.push_back(primes[j]);
    }
    if (c > 1) {
      divzq[i].push_back({c, 1});
      normm.push_back(c);
    }
  }
  sort(normm.begin(), normm.end());
  normm.erase(unique(normm.begin(), normm.end()), normm.end());
  dfs2(1, 0);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}