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>
const int con = 1000000007;
const int maxv = 10000000;
const int maxd = 18;
int n, m;
int prime[10000100];
long long pre[10000100];
int inv[10000100];
int lca[101000][20], dep[101000];
long long ans[100100];
int a[101000];
int adj[101000], subs[303000], aim[303000];
int qadj[101000], qsubs[403000], qaim[403000], cost[403000], q[101000];
int tot;
long long power(long long x, int y) {
  long long re;
  re = 1;
  while (y) {
    if (y & 1) re = re * x % con;
    x = x * x % con;
    y /= 2;
  }
  return re;
}
void builddfs(int x, int p) {
  lca[x][0] = p;
  dep[x] = dep[p] + 1;
  int i = adj[x];
  while (i > 0) {
    if (aim[i] != p) builddfs(aim[i], x);
    i = subs[i];
  }
}
void dfs(int x) {
  int temp, cumu;
  temp = a[x];
  cumu = 1;
  while (temp > 1) {
    if (cumu % prime[temp] > 0)
      cumu = prime[temp];
    else
      cumu *= prime[temp];
    pre[cumu] = pre[cumu] * prime[temp] % con;
    temp /= prime[temp];
  }
  int i;
  long long sum;
  i = qadj[x];
  while (i > 0) {
    temp = q[qaim[i]];
    cumu = 1;
    sum = 1;
    while (temp > 1) {
      if (cumu % prime[temp] > 0)
        cumu = prime[temp];
      else
        cumu *= prime[temp];
      sum = sum * pre[cumu] % con;
      temp /= prime[temp];
    }
    ans[qaim[i]] = ans[qaim[i]] * power(sum, cost[i]) % con;
    i = qsubs[i];
  }
  i = adj[x];
  while (i > 0) {
    if (aim[i] != lca[x][0]) dfs(aim[i]);
    i = subs[i];
  }
  temp = a[x];
  cumu = 1;
  while (temp > 1) {
    if (cumu % prime[temp] > 0)
      cumu = prime[temp];
    else
      cumu *= prime[temp];
    if (inv[prime[temp]] == 0) inv[prime[temp]] = power(prime[temp], con - 2);
    pre[cumu] = pre[cumu] * inv[prime[temp]] % con;
    temp /= prime[temp];
  }
}
int main() {
  pre[1] = 1;
  for (int i = 2; i <= maxv; ++i) {
    pre[i] = 1;
    if (prime[i] == 0) {
      for (int j = 1; j <= maxv; ++j) {
        if (i * j > maxv) break;
        prime[i * j] = i;
      }
    }
  }
  scanf("%d", &n);
  int u, v;
  for (int i = 1; i < n; ++i) {
    scanf("%d %d", &u, &v);
    aim[i * 2] = v;
    subs[i * 2] = adj[u];
    adj[u] = i * 2;
    aim[i * 2 + 1] = u;
    subs[i * 2 + 1] = adj[v];
    adj[v] = i * 2 + 1;
  }
  builddfs(1, 1);
  for (int j = 1; j <= maxd; ++j)
    for (int i = 1; i <= n; ++i) lca[i][j] = lca[lca[i][j - 1]][j - 1];
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("%d", &m);
  int temp;
  for (int i = 1; i <= m; ++i) {
    ans[i] = 1;
    scanf("%d %d %d", &u, &v, &q[i]);
    ++tot;
    qaim[tot] = i;
    qsubs[tot] = qadj[u];
    qadj[u] = tot;
    cost[tot] = 1;
    ++tot;
    qaim[tot] = i;
    qsubs[tot] = qadj[v];
    qadj[v] = tot;
    cost[tot] = 1;
    if (dep[u] < dep[v]) {
      temp = u;
      u = v;
      v = temp;
    }
    for (int j = maxd; j >= 0; --j)
      if (dep[lca[u][j]] >= dep[v]) u = lca[u][j];
    for (int j = maxd; j >= 0; --j) {
      if (lca[u][j] != lca[v][j]) {
        u = lca[u][j];
        v = lca[v][j];
      }
    }
    if (u != v) {
      u = lca[u][0];
    }
    ++tot;
    qaim[tot] = i;
    qsubs[tot] = qadj[u];
    qadj[u] = tot;
    cost[tot] = con - 2;
    if (u != 1) {
      u = lca[u][0];
      ++tot;
      qaim[tot] = i;
      qsubs[tot] = qadj[u];
      qadj[u] = tot;
      cost[tot] = con - 2;
    }
  }
  dfs(1);
  for (int i = 1; i <= m; ++i) printf("%I64d\n", ans[i]);
  return 0;
}