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 + 10;
const int M = 1e7 + 10;
const int Mod = 1e9 + 7;
const int P = 1e7 + 10;
map<int, int> mp;
int cntmp = 0, maxv = 0, pri = 0;
int prime[P], minp[P];
bool vis[P];
void get_prime() {
  minp[1] = 1;
  for (int i = 2; i < P; i++) {
    if (!vis[i]) {
      prime[++pri] = i;
      minp[i] = i;
    }
    for (int j = 1; j <= pri; j++) {
      if (prime[j] * i >= P) break;
      minp[prime[j] * i] = min(prime[j], minp[i]);
      vis[prime[j] * i] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
struct Edge {
  int v, nxt;
} E[N << 1];
int n, m, head[N], tot = 0;
int fa[N][17], dep[N], a[N];
void add(int u, int v) {
  E[++tot] = (Edge){v, head[u]};
  head[u] = tot;
}
void dfs_lca(int u, int father) {
  dep[u] = dep[father] + 1;
  fa[u][0] = father;
  for (int i = 1; i < 17; i++) {
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
  }
  for (int i = head[u]; i; i = E[i].nxt) {
    int v = E[i].v;
    if (v == father) continue;
    dfs_lca(v, u);
  }
}
int cal_lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int delta = dep[x] - dep[y];
  for (int i = 0; i < 17; i++)
    if ((delta >> i) & 1) x = fa[x][i];
  if (x == y) return x;
  for (int k = 16; k >= 0; k--) {
    if (fa[x][k] != fa[y][k]) {
      x = fa[x][k];
      y = fa[y][k];
    }
  }
  return fa[x][0];
}
struct Node {
  int id, val;
  bool typ;
  Node(int id = 0, int val = 0, bool typ = 0) : id(id), val(val), typ(typ) {}
};
int cnt[P], ans[N];
vector<Node> chg[N];
int mul(int a, int b) { return 1ll * a * b % Mod; }
int fast_pow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    b >>= 1;
    a = mul(a, a);
  }
  return res;
}
void modify(int pos, int val) {
  int now = a[pos];
  while (now != 1) {
    int tmp = minp[now], vl = 1;
    while (now % tmp == 0) {
      now /= tmp;
      cnt[vl *= tmp] += val;
    }
  }
}
int calc(int pos, int now) {
  int res = 1;
  while (now != 1) {
    int tmp = minp[now], vl = 1, sum = 0;
    while (now % tmp == 0) {
      now /= tmp;
      sum += cnt[vl *= tmp];
    }
    res = mul(res, fast_pow(tmp, sum));
  }
  return res;
}
void dfs(int u) {
  modify(u, 1);
  for (auto cur : chg[u]) {
    if (cur.typ) {
      ans[cur.id] = mul(ans[cur.id], calc(u, cur.val));
    } else {
      ans[cur.id] = mul(ans[cur.id], fast_pow(calc(u, cur.val), Mod - 2));
    }
  }
  for (int i = head[u]; i; i = E[i].nxt) {
    if (E[i].v == fa[u][0]) continue;
    dfs(E[i].v);
  }
  modify(u, -1);
}
int main() {
  get_prime();
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  dfs_lca(1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x, y, val;
    scanf("%d %d %d", &x, &y, &val);
    int f = cal_lca(x, y), g = fa[f][0];
    chg[x].push_back(Node(i, val, 1));
    chg[y].push_back(Node(i, val, 1));
    chg[f].push_back(Node(i, val, 0));
    chg[g].push_back(Node(i, val, 0));
    ans[i] = 1;
  }
  dfs(1);
  for (int i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}