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 MOD = 1e9 + 7, N = 101000;
int Kissme(int x, int y) {
  int c = 1;
  while (y) {
    if (y & 1) c = 1LL * x * c % MOD;
    x = 1LL * x * x % MOD;
    y >>= 1;
  }
  return c;
}
int cnt, tot, pri[N], in[N], out[N], fa[N][18], dep[N], n, T;
int b[N], tim, val[N << 1];
struct Qry {
  int u, v, l0, l1, ans;
} Q[N];
map<int, int> mp;
vector<int> g[N];
vector<pair<int, int> > o[N], q[N];
void Pre(void) {
  int lim = 1e4;
  for (int i = 2; i <= lim; i++)
    if (!b[i]) {
      pri[++cnt] = i;
      for (int j = i + i; j <= lim; j += i) b[j] = 1;
    }
}
int Get(int x) { return mp.find(x) != mp.end() ? mp[x] : mp[x] = ++tot; }
void Defact(int x, int id, int ty) {
  for (int i = 1; i <= cnt && pri[i] <= x; i++) {
    int p = pri[i];
    if (x % p == 0) {
      int now = 0;
      while (x % p == 0) {
        now++;
        x /= p;
      }
      (ty ? q : o)[Get(p)].push_back(make_pair(now, id));
    }
  }
  if (x > 1) (ty ? q : o)[Get(x)].push_back(make_pair(1, id));
}
void Dfs(int x) {
  dep[x] = dep[fa[x][0]] + 1;
  in[x] = ++tim;
  for (int i = 1; i <= 17; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (auto v : g[x])
    if (!in[v]) fa[v][0] = x, Dfs(v);
  out[x] = ++tim;
}
int Lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 17; i >= 0; i--)
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 17; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void Add(int x, int y) {
  for (; x <= tim; x += -x & x) val[x] += y;
}
int Ask(int x) {
  int ans = 0;
  for (; x; x -= -x & x) ans += val[x];
  return ans;
}
void Update(int x, int v) {
  int I = in[x], O = out[x];
  Add(I, v);
  Add(O, -v);
}
int Query(int x) {
  x = in[x];
  return Ask(x);
}
int hav[N];
int main(void) {
  scanf("%d", &n);
  Pre();
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  Dfs(1);
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    Defact(x, i, 0);
  }
  scanf("%d", &T);
  for (int i = 1; i <= T; i++) {
    int x;
    scanf("%d%d%d", &Q[i].u, &Q[i].v, &x);
    Q[i].l0 = Lca(Q[i].u, Q[i].v);
    Q[i].l1 = fa[Q[i].l0][0];
    Q[i].ans = 1;
    Defact(x, i, 1);
  }
  for (auto it : mp) {
    int p = it.first;
    if (mp.find(p) == mp.end()) continue;
    int now = mp[p];
    sort(o[now].begin(), o[now].end());
    sort(q[now].begin(), q[now].end());
    int j = 0, lst = 1;
    for (int i = 0; i < q[now].size(); i++) {
      for (; lst <= q[now][i].first; lst++) {
        while (j < o[now].size() && o[now][j].first < lst) j++;
        for (int k = j; k < o[now].size(); k++)
          Update(o[now][k].second, 1), hav[k]--;
      }
      int Qid = q[now][i].second, pw;
      pw = Query(Q[Qid].u) + Query(Q[Qid].v);
      pw -= Query(Q[Qid].l0) + Query(Q[Qid].l1);
      Q[Qid].ans = 1LL * Q[Qid].ans * Kissme(p, pw) % MOD;
    }
    for (int i = 0; i < o[now].size(); i++)
      Update(o[now][i].second, hav[i]), hav[i] = 0;
  }
  for (int i = 1; i <= T; i++) printf("%d\n", Q[i].ans);
  return 0;
}