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
#include <bits/stdc++.h>
using namespace std;
long long pow_mod(long long x, int k) {
  long long ans = 1;
  while (k) {
    if (k & 1) ans = ans * x % 1000000007;
    x = x * x % 1000000007;
    k >>= 1;
  }
  return ans;
}
int sumv[200005];
void add(int x, int num, int n) {
  for (; x <= n; x += (x & -x)) sumv[x] += num;
}
int sum(int x) {
  int s = 0;
  for (; x; x -= (x & -x)) s += sumv[x];
  return s;
}
const int maxn = 10000000;
int prime[2000000], tot;
bool check[maxn + 5];
void pre() {
  for (int i = 2; i <= maxn; i++) {
    if (!check[i]) prime[++tot] = i;
    for (int j = 1; j <= tot && i * prime[j] <= maxn; j++) {
      check[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
struct Edge {
  int t, next;
  Edge() {}
  Edge(int a, int b) : t(a), next(b) {}
};
Edge e[200005];
int head[100005];
int dep[100005], fa[100005][20];
int dfn[100005], low[100005], cnt;
void dfs(int x) {
  dfn[x] = ++cnt;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].t != fa[x][0]) {
      int u = e[i].t;
      dep[u] = dep[x] + 1;
      fa[u][0] = x;
      for (int j = 1; j < 20; j++) fa[u][j] = fa[fa[u][j - 1]][j - 1];
      dfs(u);
    }
  low[x] = ++cnt;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int d = dep[x] - dep[y];
  for (int i = 0; i < 20; i++)
    if (d & (1 << i)) x = fa[x][i];
  if (x == y) return x;
  for (int i = 19; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) {
      x = fa[x][i];
      y = fa[y][i];
    }
  return fa[x][0];
}
struct Query {
  int x, y, p;
  Query() {}
  Query(int a, int b, int c) : x(a), y(b), p(c) {}
};
Query q[100005];
long long ans[100005];
vector<pair<int, int> > vt[maxn + 5];
void getfact(int x, int y, bool on) {
  int t = x;
  for (int i = 1; i <= tot && prime[i] * prime[i] <= t; i++)
    if (x % prime[i] == 0) {
      int cnt = 0;
      while (x % prime[i] == 0) {
        cnt++;
        x /= prime[i];
        if (!on) vt[prime[i]].push_back(pair<int, int>(cnt, y));
      }
      if (on) vt[prime[i]].push_back(pair<int, int>(cnt, y));
    }
  if (x > 1) vt[x].push_back(pair<int, int>(1, y));
}
int main() {
  pre();
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[2 * i - 1] = Edge(y, head[x]);
    head[x] = 2 * i - 1;
    e[2 * i] = Edge(x, head[y]);
    head[y] = 2 * i;
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    getfact(x, i, 0);
  }
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    q[i] = Query(x, y, lca(x, y));
    ans[i] = 1;
    getfact(z, n + i, 1);
  }
  for (int i = 1; i <= maxn; i++)
    if (vt[i].size()) {
      sort(vt[i].begin(), vt[i].end());
      for (int j = 0; j < vt[i].size(); j++) {
        int t = vt[i][j].second;
        if (t <= n) {
          add(dfn[t], 1, cnt);
          add(low[t], -1, cnt);
        } else {
          t -= n;
          int s = sum(dfn[q[t].x]) + sum(dfn[q[t].y]) - sum(dfn[q[t].p]) -
                  sum(dfn[fa[q[t].p][0]]);
          ans[t] = ans[t] * pow_mod(i, s) % 1000000007;
        }
      }
      for (int j = 0; j < vt[i].size(); j++) {
        int t = vt[i][j].second;
        if (t <= n) {
          add(dfn[t], -1, cnt);
          add(low[t], 1, cnt);
        }
      }
    }
  for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}
