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;
namespace cqz {
static const int GYN = 2333333;
char SZB[GYN], *S = SZB, *T = SZB;
inline char gc() {
  if (S == T) {
    T = (S = SZB) + fread(SZB, 1, GYN, stdin);
    if (S == T) return '\n';
  }
  return *S++;
}
inline long long read() {
  long long x = 0, g = 1;
  char ch = gc();
  for (; !isdigit(ch); ch = gc())
    if (ch == '-') g = -1;
  for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch;
  return x * g;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline char readchar() {
  char ch = gc();
  for (; isspace(ch); ch = gc())
    ;
  return ch;
}
inline long long readstr(char *s) {
  char ch = gc();
  int cur = 0;
  for (; isspace(ch); ch = gc())
    ;
  for (; !isspace(ch); ch = gc()) s[cur++] = ch;
  s[cur] = '\0';
  return cur;
}
void Print(long long *a, int s, int t) {
  for (int i = int(s); i <= int(t); ++i) printf("%lld ", a[i]);
}
void Print(int *a, int s, int t) {
  for (int i = int(s); i <= int(t); ++i) printf("%d ", a[i]);
}
void Print(char *a, int s, int t) {
  for (int i = int(s); i <= int(t); ++i) putchar(a[i]);
}
void writeln(long long x) {
  write(x);
  puts("");
}
}  // namespace cqz
using namespace cqz;
const long long N = 1000010, mod = 1e9 + 7;
long long Q, ind, n, fa[200010][22], L[N], R[N], c[N], pri[N], dep[N], W[N],
    ans[N], x[N], y[N], w[N];
long long mark[10000010];
vector<long long> g[N];
vector<pair<long long, long long> > has[N];
void Init() {
  long long n = 10000000;
  for (int i = int(2); i <= int(n); ++i)
    if (!mark[i]) {
      pri[++pri[0]] = i;
      for (long long j = i; j <= n; j += i)
        mark[j] = mark[j] ? mark[j] : pri[0];
    }
}
void add(long long x, long long v) {
  for (; x <= n; x += x & -x) c[x] += v;
}
long long ask(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) ans += c[x];
  return ans;
}
void dfs(long long x) {
  L[x] = ++ind;
  for (int i = int(1); i <= int(20); ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = int(0); i < int(g[x].size()); ++i)
    if (g[x][i] != fa[x][0]) {
      long long to = g[x][i];
      dep[to] = dep[x] + 1;
      fa[to][0] = x;
      dfs(to);
    }
  R[x] = ind;
}
long long lca(long long a, long long b) {
  if (dep[a] < dep[b]) swap(a, b);
  for (int i = int(20); i >= int(0); --i)
    if (dep[a] - (1 << i) >= dep[b]) a = fa[a][i];
  for (int i = int(20); i >= int(0); --i)
    if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];
  return a == b ? a : fa[a][0];
}
void work(long long x, long long w) {
  for (; w > 1;) {
    long long cnt = 0, cur = mark[w];
    for (; !(w % pri[cur]); w /= pri[cur], ++cnt)
      if (x >= 0) has[cur].push_back(make_pair(cnt + 1, x));
    if (x < 0) has[cur].push_back(make_pair(cnt, x));
  }
}
long long ppow(long long x, long long k) {
  long long ans = 1;
  for (; k; k >>= 1, ((x) = 1LL * (x) * (x) % mod))
    if (k & 1) ((ans) = 1LL * (ans) * (x) % mod);
  return ans;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first == b.first ? (a.second > b.second) : (a.first < b.first);
}
int main() {
  n = read();
  Init();
  for (int i = int(1); i < int(n); ++i) {
    long long x = read(), y = read();
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = int(1); i <= int(n); ++i) W[i] = read();
  dfs(1);
  Q = read();
  for (int i = int(1); i <= int(n); ++i) work(i, W[i]);
  for (int i = int(1); i <= int(Q); ++i) {
    x[i] = read(), y[i] = read(), w[i] = read(), ans[i] = 1;
    work(-i, w[i]);
  }
  for (int i = int(1); i <= int(pri[0]); ++i)
    if (has[i].size()) {
      sort(has[i].begin(), has[i].end(), cmp);
      for (int j = int(0); j < int(has[i].size()); ++j) {
        if (has[i][j].second >= 0) {
          add(L[has[i][j].second], 1);
          add(R[has[i][j].second] + 1, -1);
        } else {
          long long a = x[-has[i][j].second], b = y[-has[i][j].second],
                    Lca = lca(a, b),
                    Value = ask(L[a]) + ask(L[b]) - ask(L[Lca]) -
                            ask(L[fa[Lca][0]]);
          ((ans[-has[i][j].second]) =
               1LL * (ans[-has[i][j].second]) * (ppow(pri[i], Value)) % mod);
        }
      }
      for (int j = int(0); j < int(has[i].size()); ++j)
        if (has[i][j].second >= 0) {
          add(L[has[i][j].second], -1);
          add(R[has[i][j].second] + 1, 1);
        }
    }
  for (int i = int(1); i <= int(Q); ++i) writeln(ans[i]);
}