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 GCC optimize("no-stack-protector")
using namespace std;
const int MAXBUF = 1000005;
char B[MAXBUF], *Si = B, *Ti = B;
inline char getc() {
  if (Si == Ti) Ti = (Si = B) + fread(B, 1, MAXBUF, stdin);
  if (Si == Ti) return 0;
  return *Si++;
}
template <class T>
inline void read(T &a) {
  static char c;
  while ((c = getc()) < '0' || c > '9')
    ;
  a = c - '0';
  while ((c = getc()) >= '0' && c <= '9') a = (a << 3) + (a << 1) + c - '0';
}
char Buff[MAXBUF], *sti = Buff;
template <class T>
inline void write(T a) {
  static char c[20];
  static int c0;
  c0 = 0;
  while (a) c[c0++] = a % 10 + '0', a /= 10;
  while (c0--) *sti++ = c[c0];
}
const int LM = 4000;
int head[100005], nxt[200005], v[200005], tot = 0;
int fa[100005], son[100005], sz[100005], top[100005];
int fla[10000005], pri[1000005], dep[100005], cnt = 0, n, m;
int c1[100005], c2[100005], res[100005];
int t1[4005][25], t2[10000005];
int ans[100005][11];
bool isp[10000005];
pair<int, int> p[100005][11];
pair<int, int> q[100005][11];
vector<int> inc[100005];
vector<int> del[100005];
inline int qpow(int a, int b) {
  int res = 1, tp = a;
  while (b) {
    if (b & 1) res = 1ll * res * tp % 1000000007;
    tp = 1ll * tp * tp % 1000000007;
    b >>= 1;
  }
  return res;
}
inline void add(int a, int b) {
  tot++;
  nxt[tot] = head[a];
  head[a] = tot;
  v[tot] = b;
}
inline void getp() {
  for (int i = 2; i <= 10000000; i++) {
    if (!isp[i]) {
      fla[i] = i;
      pri[++cnt] = i;
    }
    for (int j = 1; j <= cnt && i * pri[j] <= 10000000; j++) {
      fla[i * pri[j]] = pri[j];
      isp[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
void dfs(int pos, int f) {
  sz[pos] = 1;
  for (int i = head[pos]; i; i = nxt[i]) {
    if (v[i] == f) continue;
    dep[v[i]] = dep[pos] + 1;
    fa[v[i]] = pos;
    dfs(v[i], pos);
    sz[pos] += sz[v[i]];
    if (sz[v[i]] > sz[son[pos]]) son[pos] = v[i];
  }
}
void dfs2(int pos, int tp) {
  top[pos] = tp;
  if (son[pos]) dfs2(son[pos], tp);
  for (int i = head[pos]; i; i = nxt[i]) {
    if (v[i] == fa[pos]) continue;
    if (v[i] == son[pos]) continue;
    dfs2(v[i], v[i]);
  }
}
inline int lca(int a, int b) {
  while (top[a] ^ top[b]) {
    if (dep[top[a]] < dep[top[b]]) swap(a, b);
    a = fa[top[a]];
  }
  return (dep[a] < dep[b] ? a : b);
}
void work(int pos, int f) {
  int i, j, k;
  int s1 = inc[pos].size();
  int s2 = del[pos].size();
  for (i = 1; i <= c1[pos]; i++) {
    int num = p[pos][i].first;
    int o = p[pos][i].second;
    if (num <= LM) {
      for (j = 1; j <= o; j++) t1[num][j]++;
      continue;
    }
    t2[num]++;
  }
  for (i = 0; i < s1; i++) {
    int id = inc[pos][i];
    for (j = 1; j <= c2[id]; j++) {
      int num = q[id][j].first;
      int o = q[id][j].second;
      if (num <= LM) {
        for (k = 1; k <= o; k++) ans[id][j] += t1[num][k];
        continue;
      }
      ans[id][j] += t2[num];
    }
  }
  for (i = 0; i < s2; i++) {
    int id = del[pos][i];
    for (j = 1; j <= c2[id]; j++) {
      int num = q[id][j].first;
      int o = q[id][j].second;
      if (num <= LM) {
        for (k = 1; k <= o; k++) ans[id][j] -= t1[num][k];
        continue;
      }
      ans[id][j] -= t2[num];
    }
  }
  for (i = head[pos]; i; i = nxt[i]) {
    if (v[i] == f) continue;
    work(v[i], pos);
  }
  for (i = 1; i <= c1[pos]; i++) {
    int num = p[pos][i].first;
    int o = p[pos][i].second;
    if (num <= LM) {
      for (j = 1; j <= o; j++) t1[num][j]--;
      continue;
    }
    t2[num]--;
  }
}
int main() {
  int a, b, x, i, j;
  getp();
  read(n);
  for (i = 1; i < n; i++) {
    read(a);
    read(b);
    add(a, b);
    add(b, a);
  }
  dfs(1, 0);
  dfs2(1, 1);
  for (i = 1; i <= n; i++) {
    read(x);
    while (x != 1) {
      int t = fla[x], o = 0;
      while (x % t == 0) x /= t, o++;
      p[i][++c1[i]] = make_pair(t, o);
    }
  }
  read(m);
  for (i = 1; i <= m; i++) {
    read(a);
    read(b);
    read(x);
    int t = lca(a, b);
    while (x != 1) {
      int t = fla[x], o = 0;
      while (x % t == 0) x /= t, o++;
      q[i][++c2[i]] = make_pair(t, o);
    }
    inc[a].push_back(i);
    inc[b].push_back(i);
    del[t].push_back(i);
    del[fa[t]].push_back(i);
  }
  work(1, 0);
  for (i = 1; i <= m; i++) {
    int res = 1;
    for (j = 1; j <= c2[i]; j++)
      res = 1ll * res * qpow(q[i][j].first, ans[i][j]) % 1000000007;
    write(res), *sti++ = '\n';
  }
  fwrite(Buff, 1, sti - Buff, stdout);
  return 0;
}