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>
#pragma warning(disable : 4996)
template <typename T>
T min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
T max(T x, T y) {
  return x > y ? x : y;
};
const int MAXN = 100005;
const long long mod = 1000000007;
long long qpow(long long x, long long y) {
  if (!y) return 1;
  long long t = qpow(x, y / 2);
  t = t * t % mod;
  if (y & 1) t = t * x % mod;
  return t;
}
std::pair<int, int> V[100];
int VS;
void sperate(int x) {
  int t = x;
  VS = 0;
  for (int i = 2; i * i <= x; i++) {
    if (t % i) continue;
    int cnt = 0;
    while (t % i == 0) cnt++, t /= i;
    V[++VS] = std::make_pair(i, cnt);
  }
  if (t > 1) V[++VS] = std::make_pair(t, 1);
}
struct node {
  int to;
  node *next;
};
void addnode(node *&head, int to) {
  node *p = new node;
  p->to = to;
  p->next = head;
  head = p;
}
struct opt {
  int ty;
  int val;
  int num;
  int pos;
  int tag;
  opt(int t = 0, int v = 0, int n = 0, int p = 0, int ta = 0) {
    ty = t;
    val = v;
    num = n;
    pos = p;
    tag = ta;
  }
  bool operator<(opt t) const {
    if (val != t.val) return val < t.val;
    if (num != t.num) return num < t.num;
    return ty < t.ty;
  }
};
int N, M;
long long ans[MAXN];
node *edge[MAXN];
int rank[MAXN], mxr[MAXN], fa[MAXN][25], dep[MAXN];
opt op[MAXN * 50];
int cnt;
int dfs_clock;
void dfs(int v, int f) {
  dep[v] = dep[f] + 1;
  fa[v][0] = f;
  for (int i = 1; i < 25; i++) fa[v][i] = fa[fa[v][i - 1]][i - 1];
  rank[v] = ++dfs_clock;
  for (node *p = edge[v]; p; p = p->next)
    if (p->to != f) dfs(p->to, v);
  mxr[v] = dfs_clock;
}
int LCA(int x, int y) {
  if (dep[y] > dep[x]) std::swap(x, y);
  int d = dep[x] - dep[y];
  for (int i = 0; i < 25; i++)
    if (d & (1 << i)) x = fa[x][i];
  if (x == y) return x;
  for (int i = 24; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void init() {
  int u, v, w;
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    scanf("%d %d", &u, &v);
    addnode(edge[u], v);
    addnode(edge[v], u);
  }
  dfs(1, 0);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &u);
    sperate(u);
    for (std::pair<int, int> *it = V + 1; it != V + VS + 1; it++)
      op[++cnt] = opt(0, (*it).first, (*it).second, i);
  }
  scanf("%d", &M);
  for (int i = 1; i <= M; i++) {
    ans[i] = 1;
    scanf("%d %d %d", &u, &v, &w);
    sperate(w);
    for (std::pair<int, int> *it = V + 1; it != V + VS + 1; it++)
      op[++cnt] = opt(i, (*it).first, (*it).second, u, v);
  }
  std::sort(op + 1, op + cnt + 1);
}
struct tree {
  long long bit[MAXN];
  void modify(int l, int r, int k) {
    for (int i = l; i < MAXN; i += ((i) & -(i))) bit[i] += k;
    for (int i = r + 1; i < MAXN; i += ((i) & -(i))) bit[i] -= k;
  }
  long long query(int id) {
    long long ret = 0;
    for (int i = id; i; i -= ((i) & -(i))) ret += bit[i];
    return ret;
  }
};
tree T1, T2;
void solve() {
  for (int i = 1; i <= cnt && op[i].val == op[1].val; i++)
    if (!op[i].ty) T2.modify(rank[op[i].pos], mxr[op[i].pos], 1);
  for (int i = 1; i <= cnt; i++) {
    if (i > 1 && op[i].val != op[i - 1].val) {
      for (int j = i - 1; j && op[j].val == op[i - 1].val; j--)
        if (!op[j].ty) T1.modify(rank[op[j].pos], mxr[op[j].pos], -op[j].num);
      for (int j = i; j <= cnt && op[j].val == op[i].val; j++)
        if (!op[j].ty) T2.modify(rank[op[j].pos], mxr[op[j].pos], 1);
    }
    if (!op[i].ty) {
      T1.modify(rank[op[i].pos], mxr[op[i].pos], op[i].num);
      T2.modify(rank[op[i].pos], mxr[op[i].pos], -1);
    } else {
      long long t = 0;
      t += T1.query(rank[op[i].pos]);
      t += T2.query(rank[op[i].pos]) * op[i].num;
      t += T1.query(rank[op[i].tag]);
      t += T2.query(rank[op[i].tag]) * op[i].num;
      int lca = LCA(op[i].pos, op[i].tag);
      t -= T1.query(rank[lca]);
      t -= T2.query(rank[lca]) * op[i].num;
      t -= T1.query(rank[fa[lca][0]]);
      t -= T2.query(rank[fa[lca][0]]) * op[i].num;
      ans[op[i].ty] = ans[op[i].ty] * qpow(op[i].val, t) % mod;
    }
  }
}
int main() {
  init();
  solve();
  for (int i = 1; i <= M; i++) printf("%I64d\n", ans[i]);
  return 0;
}