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;
char cb[1 << 16], *cs = cb, *ct = cb;
void read(int &res) {
  char ch;
  for (; !isdigit(
           ch = (cs == ct && (ct = (cs = cb) + fread(cb, 1, 1 << 16, stdin),
                             cs == ct)
                     ? 0
                     : *cs++));)
    ;
  for (res = ch - '0';
       isdigit(ch = (cs == ct && (ct = (cs = cb) + fread(cb, 1, 1 << 16, stdin),
                                 cs == ct)
                         ? 0
                         : *cs++));
       res = res * 10 + ch - '0')
    ;
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int Pow(int b, int k) {
  int r = 1;
  for (; k; k >>= 1, b = 1ll * b * b % 1000000007)
    if (k & 1) r = 1ll * r * b % 1000000007;
  return r;
}
int pr[10000007], vis[10000007], cnt_pr, mpr[10000007], inv[10000007],
    a[100005], ans[100005], iva[100005];
int n;
int info[100005], Prev[100005 << 1], to[100005 << 1], cnt_e;
void Node(int u, int v) {
  Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v;
}
int dep[100005], f[17][100005], sx[100005], ty[100005], cw[100005];
void dfs0(int u, int ff) {
  dep[u] = dep[f[0][u] = ff] + 1;
  for (int i = info[u], v; i; i = Prev[i])
    if ((v = to[i]) ^ ff) dfs0(v, u);
}
int Lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 0; dep[u] ^ dep[v]; i++)
    if (dep[u] - dep[v] >> i & 1) u = f[i][u];
  if (u == v) return u;
  for (int i = 17 - 1; i >= 0; i--)
    if (f[i][u] ^ f[i][v]) u = f[i][u], v = f[i][v];
  return f[0][u];
}
vector<pair<int, int> > G[100005];
int sm[10000007];
void dfs(int u, int ff) {
  for (int v = a[u], t; v > 1;) {
    t = mpr[v];
    for (int pw = t; v % t == 0; pw *= t) {
      v /= t;
      sm[pw] = 1ll * sm[pw] * t % 1000000007;
    }
  }
  for (int i = (0), LIM = (G[u].size() - 1); i <= LIM; i++) {
    int v = G[u][i].first, tp = G[u][i].second;
    for (int t = cw[v], p; t > 1;) {
      p = mpr[t];
      for (int pw = p; t % p == 0; pw *= p) {
        t /= p;
        if (tp == 1)
          ans[v] = 1ll * ans[v] * sm[pw] % 1000000007;
        else
          iva[v] = 1ll * iva[v] * sm[pw] % 1000000007;
      }
    }
  }
  for (int i = info[u], v; i; i = Prev[i])
    if ((v = to[i]) ^ ff) dfs(v, u);
  for (int v = a[u], t; v > 1;) {
    t = mpr[v];
    for (int pw = t; v % t == 0; pw *= t) {
      v /= t;
      sm[pw] = 1ll * sm[pw] * inv[t] % 1000000007;
    }
  }
}
int main() {
  inv[1] = sm[1] = 1;
  for (int i = 2; i < 10000007; i++) {
    sm[i] = 1;
    if (!vis[i]) pr[cnt_pr++] = i, mpr[i] = i, inv[i] = Pow(i, 1000000007 - 2);
    for (int j = 0; pr[j] * i < 10000007; j++) {
      vis[i * pr[j]] = 1;
      inv[i * pr[j]] = 1ll * inv[i] * inv[pr[j]] % 1000000007;
      mpr[i * pr[j]] = pr[j];
      if (i % pr[j] == 0) break;
    }
  }
  read(n);
  for (int i = (1), LIM = (n - 1); i <= LIM; i++) {
    int u, v;
    read(u), read(v);
    Node(u, v), Node(v, u);
  }
  dfs0(1, 0);
  for (int i = (1), LIM = (n); i <= LIM; i++) read(a[i]);
  for (int j = (1), LIM = (17 - 1); j <= LIM; j++)
    for (int i = (1), LIM = (n); i <= LIM; i++) f[j][i] = f[j - 1][f[j - 1][i]];
  int q;
  read(q);
  for (int i = (1), LIM = (q); i <= LIM; i++) {
    read(sx[i]), read(ty[i]), read(cw[i]);
    int t = Lca(sx[i], ty[i]);
    G[sx[i]].push_back(make_pair(i, 1)), G[ty[i]].push_back(make_pair(i, 1)),
        G[t].push_back(make_pair(i, -1));
    ans[i] = gcd(a[t], cw[i]), iva[i] = 1;
  }
  dfs(1, 0);
  for (int i = (1), LIM = (q); i <= LIM; i++)
    printf("%d\n", 1ll * ans[i] * Pow(iva[i], 1000000007 - 3) % 1000000007);
}