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;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 1;
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  if (f) x = -x;
}
template <typename F>
inline void write(F x, char ed = '\n') {
  static short st[30];
  short tp = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++tp] = x % 10, x /= 10;
  while (x);
  while (tp) putchar('0' | st[tp--]);
  putchar(ed);
}
template <typename T>
inline void write(T *st, int n, string s = "") {
  if (s.size()) cout << s << ": ";
  while (n--) write(*st++, ' ');
  puts("");
}
const int N = 100500;
const int M = 10000500;
const int P = 1e9 + 7;
int ne[N << 1], to[N << 1], h[N], dfn[N], Top[N], son[N], siz[N], id[N], num,
    dep[N], tot;
inline void add(int x, int y) { ne[++tot] = h[x], to[h[x] = tot] = y; }
long long fpw(long long x, long long mi) {
  long long res = 1;
  for (; mi; mi >>= 1, x = x * x % P)
    if (mi & 1) res = res * x % P;
  return res;
}
long long ans[N];
int f[N], pr[M], e[M], val[N], totp;
int d[M], len[M], st[M], nw = 0, n, q;
void prework(int lim) {
  for (int i = 2; i <= lim; ++i) {
    if (!e[i]) pr[++totp] = e[i] = i;
    if (e[i] == i) {
      st[i] = nw;
      int k = lim;
      while (k) ++nw, ++len[i], k /= i;
    }
    for (int j = 1; j <= totp && pr[j] * i <= lim; ++j) {
      e[pr[j] * i] = pr[j];
      if (pr[j] == e[i]) break;
    }
  }
}
void dfs1(int x, int fa) {
  dep[x] = dep[f[x] = fa] + (siz[x] = 1);
  for (int i = h[x], y; i; i = ne[i]) {
    if ((y = to[i]) == fa) continue;
    dfs1(y, x), siz[x] += siz[y];
    if (siz[y] > siz[son[x]]) son[x] = y;
  }
}
void dfs2(int x, int topf) {
  Top[x] = topf, id[dfn[x] = ++num] = x;
  if (son[x]) dfs2(son[x], topf);
  for (int i = h[x], y; i; i = ne[i])
    if (!dfn[y = to[i]]) dfs2(y, y);
}
int Lca(int x, int y) {
  while (Top[x] != Top[y]) {
    if (dep[Top[x]] < dep[Top[y]]) swap(x, y);
    x = f[Top[x]];
  }
  return dep[x] < dep[y] ? x : y;
}
vector<pair<int, int> > qry[N];
void getans(int x, int fa) {
  int tx = val[x];
  while (tx != 1) {
    int p = e[tx], mi = 0;
    while (tx % p == 0) tx /= p, ++mi;
    for (int i = 1; i <= mi; ++i) d[st[p] + i - 1] += i;
    for (int i = mi + 1; i <= len[p]; ++i) d[st[p] + i - 1] += mi;
  }
  for (auto t : qry[x]) {
    tx = t.second;
    long long mul = 1;
    while (tx != 1) {
      int p = e[tx], mi = 0;
      while (tx % p == 0) tx /= p, ++mi;
      mul = mul * fpw(p, d[st[p] + mi - 1]) % P;
    }
    if (t.first > 0)
      ans[t.first] = ans[t.first] * mul % P;
    else
      ans[-t.first] = ans[-t.first] * fpw(mul, P - 2) % P;
  }
  for (int i = h[x]; i; i = ne[i])
    if (to[i] != fa) getans(to[i], x);
  tx = val[x];
  while (tx != 1) {
    int p = e[tx], mi = 0;
    while (tx % p == 0) tx /= p, ++mi;
    for (int i = 1; i <= mi; ++i) d[st[p] + i - 1] -= i;
    for (int i = mi + 1; i <= len[p]; ++i) d[st[p] + i - 1] -= mi;
  }
}
int main() {
  read(n);
  for (int i = 1, x, y; i < n; ++i) read(x), read(y), add(x, y), add(y, x);
  dfs1(1, 0), dfs2(1, 1), prework(1e7);
  for (int i = 1; i <= n; ++i) read(val[i]);
  read(q);
  for (int i = 1, x, y, t; i <= q; ++i) {
    read(x), read(y), read(t), ans[i] = 1;
    qry[x].push_back(make_pair(i, t));
    qry[y].push_back(make_pair(i, t));
    qry[Lca(x, y)].push_back(make_pair(-i, t));
    qry[f[Lca(x, y)]].push_back(make_pair(-i, t));
  }
  getans(1, 0);
  for (int i = 1; i <= q; ++i) write(ans[i]);
  return 0;
}