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 = 100005;
const int M = 10000005;
const int mo = 1000000007;
int pri[M / 10], mn[M], id[M];
vector<int> e[N];
int n, T, Q, dfn[N], ed[N];
int fa[N][20], dep[N];
int qx[N], qy[N], qL[N], qv[N];
int t[N * 2], vis[N], A[N], ans[N];
vector<int> vec[M / 10];
pair<int, int> q1[N], q2[N];
int power(int x, int y) {
  int s = 1;
  for (; y; y /= 2, x = 1ll * x * x % mo)
    if (y & 1) s = 1ll * s * x % mo;
  return s;
}
void change(int x, int v) {
  for (; x <= 2 * n; x += x & (-x)) t[x] += v;
}
int ask(int x) {
  int ans = 0;
  for (; x; x -= x & (-x)) ans += t[x];
  return ans;
}
void init() {
  for (int i = (int)(2); i <= (int)(M - 1); i++) {
    if (!mn[i]) mn[i] = i, pri[++*pri] = i;
    for (int j = 1; j <= *pri && i * pri[j] < M; ++j) {
      mn[i * pri[j]] = pri[j];
      if (i % pri[j] == 0) break;
    }
  }
  for (int i = (int)(1); i <= (int)(*pri); i++) id[pri[i]] = i;
}
void insert(int x, int id) {
  for (; x != 1;) {
    int v = mn[x];
    for (; x % v == 0; x /= v)
      ;
    vec[::id[v]].push_back(id);
  }
}
void dfs(int x) {
  dfn[x] = ++*dfn;
  for (auto i : e[x])
    if (i != fa[x][0]) {
      fa[i][0] = x;
      dep[i] = dep[x] + 1;
      dfs(i);
    }
  ed[x] = ++*dfn;
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int tmp = dep[x] - dep[y];
  for (int i = (int)(0); i <= (int)(18); i++)
    if (tmp & (1 << i)) x = fa[x][i];
  for (int i = (int)(18); i >= (int)(0); i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return x == y ? x : fa[x][0];
}
void solve(int id) {
  int top1 = 0, top2 = 0;
  for (auto i : vec[id])
    if (i < 0)
      q2[++top2] = pair<int, int>(-i, qv[-i]);
    else
      q1[++top1] = pair<int, int>(i, A[i]);
  for (; top1 && top2;) {
    int tmp1 = 0, tmp2 = 0;
    for (int i = (int)(1); i <= (int)(top1); i++) {
      change(dfn[q1[i].first], -1);
      change(ed[q1[i].first], 1);
    }
    for (int i = (int)(1); i <= (int)(top2); i++) {
      int at = q2[i].first;
      int val1 = ask(ed[qL[at]] - 1) - ask(ed[qx[at]] - 1);
      int val2 = ask(ed[qL[at]]) - ask(ed[qy[at]] - 1);
      ans[at] = 1ll * ans[at] * power(pri[id], val1 + val2) % mo;
    }
    for (int i = (int)(1); i <= (int)(top1); i++) {
      change(dfn[q1[i].first], 1);
      change(ed[q1[i].first], -1);
    }
    for (int i = (int)(1); i <= (int)(top1); i++) q1[i].second /= pri[id];
    for (int i = (int)(1); i <= (int)(top2); i++) q2[i].second /= pri[id];
    for (int i = (int)(1); i <= (int)(top1); i++)
      if (q1[i].second % pri[id] == 0) q1[++tmp1] = q1[i];
    for (int i = (int)(1); i <= (int)(top2); i++)
      if (q2[i].second % pri[id] == 0) q2[++tmp2] = q2[i];
    top1 = tmp1;
    top2 = tmp2;
  }
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1);
  for (int i = (int)(1); i <= (int)(18); i++)
    for (int j = (int)(1); j <= (int)(n); j++)
      fa[j][i] = fa[fa[j][i - 1]][i - 1];
  for (int i = (int)(1); i <= (int)(n); i++) {
    scanf("%d", &A[i]);
    insert(A[i], i);
  }
  scanf("%d", &Q);
  for (int i = (int)(1); i <= (int)(Q); i++) {
    scanf("%d%d%d", &qx[i], &qy[i], &qv[i]);
    qL[i] = LCA(qx[i], qy[i]);
    insert(qv[i], -i);
    ans[i] = 1;
  }
  for (int i = (int)(1); i <= (int)(*pri); i++) solve(i);
  for (int i = (int)(1); i <= (int)(Q); i++) printf("%d\n", ans[i]);
}