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 N = 1e5 + 5;
const int P = 1e7 + 5;
const int MOD = 1e9 + 7;
int n, q, pn;
int isp[P];
int a[N], c[N];
int dep[N], fa[25][N];
int ans[N];
int ct[N * 10][30];
int mt[N * 10][30];
vector<int> nei[N];
vector<pair<int, int> > qry[N];
int Pow(int x, int y) {
  int rt = 1, mt = x;
  while (y) {
    if (y & 1) rt = 1ll * rt * mt % MOD;
    y >>= 1;
    mt = 1ll * mt * mt % MOD;
  }
  return rt;
}
void dfs(int x) {
  for (int i = 0; i < int(nei[x].size()); i++) {
    int to = nei[x][i];
    if (to == fa[0][x]) continue;
    fa[0][to] = x;
    dep[to] = dep[x] + 1;
    dfs(to);
  }
}
void cal(int x) {
  int y = a[x];
  for (int i = 2; i * i <= y; i++)
    if (y % i == 0) {
      int pw = 0;
      while (y % i == 0) {
        pw++;
        y /= i;
      }
      ct[isp[i]][pw]++;
      mt[isp[i]][pw] = 1ll * mt[isp[i]][pw] * Pow(i, pw) % MOD;
    }
  if (y != 1) {
    ct[isp[y]][1]++;
    mt[isp[y]][1] = 1ll * mt[isp[y]][1] * y % MOD;
  }
  for (int i = 0; i < int(qry[x].size()); i++) {
    int qr = qry[x][i].first;
    y = c[qr];
    for (int j = 2; j * j <= y; j++)
      if (y % j == 0) {
        int pw = 0;
        while (y % j == 0) {
          pw++;
          y /= j;
        }
        int tot = 0, mul = 1;
        for (int k = 1; k <= pw; k++) mul = 1ll * mul * mt[isp[j]][k] % MOD;
        for (int k = pw + 1; k <= 25; k++) tot += ct[isp[j]][k];
        mul = 1ll * mul * Pow(j, pw * tot) % MOD;
        if (qry[x][i].second == 1)
          ans[qr] = 1ll * ans[qr] * mul % MOD;
        else
          ans[qr] = 1ll * ans[qr] * Pow(mul, MOD - 2) % MOD;
      }
    if (y != 1) {
      int pw = 1;
      int tot = 0, mul = 1;
      for (int k = 1; k <= pw; k++) mul = 1ll * mul * mt[isp[y]][k] % MOD;
      for (int k = pw + 1; k <= 25; k++) tot += ct[isp[y]][k];
      mul = 1ll * mul * Pow(y, pw * tot) % MOD;
      if (qry[x][i].second == 1)
        ans[qr] = 1ll * ans[qr] * mul % MOD;
      else
        ans[qr] = 1ll * ans[qr] * Pow(mul, MOD - 2) % MOD;
    }
  }
  for (int i = 0; i < int(nei[x].size()); i++) {
    int to = nei[x][i];
    if (to == fa[0][x]) continue;
    cal(to);
  }
  y = a[x];
  for (int i = 2; i * i <= y; i++)
    if (y % i == 0) {
      int pw = 0;
      while (y % i == 0) {
        pw++;
        y /= i;
      }
      ct[isp[i]][pw]--;
      mt[isp[i]][pw] = 1ll * mt[isp[i]][pw] * Pow(Pow(i, pw), MOD - 2) % MOD;
    }
  if (y != 1) {
    ct[isp[y]][1]--;
    mt[isp[y]][1] = 1ll * mt[isp[y]][1] * Pow(y, MOD - 2) % MOD;
  }
}
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  for (int i = 0; i < 24; i++)
    if ((dep[y] - dep[x]) & (1 << i)) y = fa[i][y];
  if (x == y) return x;
  for (int i = 23; i >= 0; i--)
    if (fa[i][x] != fa[i][y]) x = fa[i][x], y = fa[i][y];
  return fa[0][x];
}
int main() {
  for (int i = 0; i < N * 10; i++)
    for (int j = 0; j < 30; j++) mt[i][j] = 1;
  for (int i = 2; i < P; i++) isp[i] = 1;
  for (int i = 2; i < P; i++)
    if (isp[i]) {
      isp[i] = ++pn;
      for (int j = 2; i * j < P; j++) isp[i * j] = 0;
    }
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    nei[x].push_back(y);
    nei[y].push_back(x);
  }
  fa[0][1] = 1;
  dfs(1);
  for (int i = 0; i < 24; i++)
    for (int j = 1; j <= n; j++) fa[i + 1][j] = fa[i][fa[i][j]];
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y, l;
    scanf("%d%d%d", &x, &y, c + i);
    l = lca(x, y);
    if (l != 1) qry[fa[0][l]].push_back(make_pair(i, -1));
    qry[l].push_back(make_pair(i, -1));
    qry[x].push_back(make_pair(i, 1));
    qry[y].push_back(make_pair(i, 1));
    ans[i] = 1;
  }
  cal(1);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}