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 long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int M = 201000;
const int N = 10000000;
int l[M], dep[M], r[M], VV, Q, tot, p[M][20], q, mm[M * 2];
vector<int> e[M];
int fst[N + 100], y[M * 2], nxt[M * 2];
pair<int, int> vec[M * 2];
int que[M * 2];
long long ret[M];
void dfs(int u, int f) {
  l[u] = ++tot;
  p[u][0] = f;
  dep[u] = dep[f] + 1;
  for (int j = 0; j < ((int)(e[u]).size()); j++)
    if (e[u][j] != f) dfs(e[u][j], u);
  r[u] = tot;
}
int lca(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (int i = 18 - 1; i >= 0; i--)
    if (dep[p[v][i]] >= dep[u]) v = p[v][i];
  if (u == v) return u;
  for (int i = 18 - 1; i >= 0; i--)
    if (p[v][i] != p[u][i]) u = p[u][i], v = p[v][i];
  return p[u][0];
}
int pr[N / 5], pp[N + 100];
bool mark[N + 100];
void add(int u, int v) {
  tot++;
  y[tot] = v;
  nxt[tot] = fst[u];
  fst[u] = tot;
}
void init() {
  pp[1] = 1;
  for (int i = 2; i < N + 1; i++) {
    if (!pp[i]) {
      pp[i] = i, pr[++tot] = i;
      long long v = i;
      while (v <= N) {
        mark[v] = 1;
        v = v * i;
      }
    }
    for (int j = 1; j <= tot && pr[j] * i <= N; j++) {
      pp[i * pr[j]] = pr[j];
      if (pp[i] == pr[j]) break;
    }
  }
}
int n, u, v, a[M], U[M], V[M], W[M], z[M];
int query(int x) {
  x = l[x];
  auto it = lower_bound(vec + 1, vec + VV + 1, make_pair(x + 1, -(int)1e9)) - 1;
  return it->second;
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  tot = 0;
  dfs(1, 0);
  for (int j = 1; j < 18; j++)
    for (int i = 1; i < n + 1; i++) p[i][j] = p[p[i][j - 1]][j - 1];
  tot = 0;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", a + i);
    add(a[i], i);
  }
  scanf("%d", &q);
  for (int i = 1; i < q + 1; i++) {
    scanf("%d%d%d", U + i, V + i, W + i);
    z[i] = lca(U[i], V[i]);
    add(W[i], -i);
    ret[i] = 1;
  }
  for (int i = 2; i < N + 1; i++)
    if (mark[i]) {
      Q = 0;
      VV = 0;
      int pr = pp[i];
      for (int j = i; j <= N; j += i) {
        for (int k = fst[j]; k; k = nxt[k]) {
          int z = y[k];
          if (mm[z + 100001] == i) continue;
          mm[z + 100001] = i;
          if (z > 0) {
            vec[++VV] = make_pair(l[z], 1);
            vec[++VV] = make_pair(r[z] + 1, -1);
          } else
            que[Q++] = -z;
        }
      }
      if (Q == 0 || VV == 0) continue;
      sort(vec + 1, vec + VV + 1);
      for (int i = 1; i < VV + 1; i++) vec[i].second += vec[i - 1].second;
      for (int c = 0; c < Q; c++) {
        int j = que[c];
        int cnt = query(U[j]) + query(V[j]) - query(z[j]) - query(p[z[j]][0]);
        ret[j] = ret[j] * powmod(pr, cnt) % mod;
      }
    }
  for (int i = 1; i < q + 1; i++) printf("%lld\n", ret[i]);
}