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 Maxn = 100010;
const int lg = 18;
const long long Mod = 1e9 + 7;
int minp[10000010], pr[1000010], prl, po[10000010];
void pre() {
  minp[1] = 1;
  for (int i = 2; i <= 10000000; i++) {
    if (!minp[i]) minp[i] = i, pr[++prl] = i, po[i] = prl;
    for (int j = 1; j <= prl && i * pr[j] <= 10000000; j++) {
      minp[i * pr[j]] = pr[j];
      if (i % pr[j] == 0) break;
    }
  }
}
struct node {
  int y, next;
} a[Maxn << 1];
int first[Maxn], len;
void ins(int x, int y) {
  len++;
  a[len].y = y;
  a[len].next = first[x];
  first[x] = len;
}
int n, m;
int na[Maxn];
int fa[Maxn][lg], dep[Maxn];
long long ans[Maxn];
int qq[Maxn];
vector<int> vec[Maxn], fl[Maxn];
int ss[1000010][25];
void dfs(int x) {
  for (int i = 1; i < lg; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int k = first[x]; k; k = a[k].next) {
    int y = a[k].y;
    if (y == fa[x][0]) continue;
    fa[y][0] = x;
    dep[y] = dep[x] + 1;
    dfs(y);
  }
}
int getlca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = lg - 1; i >= 0; i--) {
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  }
  if (x == y) return x;
  for (int i = lg - 1; i >= 0; i--) {
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  }
  return fa[x][0];
}
int pi[lg], ri[lg], K;
void fj(int x) {
  K = 0;
  while (x > 1) {
    if (minp[x] == pi[K])
      ri[K]++;
    else
      pi[++K] = minp[x], ri[K] = 1;
    x /= minp[x];
  }
}
long long qpow(long long x, int k) {
  long long ret = 1;
  while (k) {
    if (k & 1) ret = ret * x % Mod;
    x = x * x % Mod;
    k >>= 1;
  }
  return ret;
}
void dfs2(int x) {
  fj(na[x]);
  int i, j, k;
  for (i = 1; i <= K; i++) ss[po[pi[i]]][ri[i]]++;
  for (i = 0; i < vec[x].size(); i++) {
    int num = vec[x][i];
    fj(qq[num]);
    for (j = 1; j <= K; j++) {
      int ps = 0;
      for (k = 1; k < 25; k++) {
        if (k <= ri[j])
          ps += ss[po[pi[j]]][k] * k;
        else
          ps += ss[po[pi[j]]][k] * ri[j];
      }
      if (fl[x][i] == 1)
        ans[num] = ans[num] * qpow(pi[j], ps) % Mod;
      else
        ans[num] = ans[num] * qpow(qpow(pi[j], ps), Mod - 2) % Mod;
    }
  }
  for (k = first[x]; k; k = a[k].next) {
    int y = a[k].y;
    if (y == fa[x][0]) continue;
    dfs2(y);
  }
  fj(na[x]);
  for (i = 1; i <= K; i++) ss[po[pi[i]]][ri[i]]--;
}
int main() {
  int i, j, k;
  pre();
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ins(x, y);
    ins(y, x);
  }
  dep[1] = 1;
  dfs(1);
  for (i = 1; i <= n; i++) scanf("%d", &na[i]);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    int x, y;
    ans[i] = 1;
    scanf("%d%d%d", &x, &y, &qq[i]);
    int lca = getlca(x, y);
    vec[x].push_back(i);
    fl[x].push_back(1);
    vec[y].push_back(i);
    fl[y].push_back(1);
    vec[lca].push_back(i);
    fl[lca].push_back(-1);
    vec[fa[lca][0]].push_back(i);
    fl[fa[lca][0]].push_back(-1);
  }
  dfs2(1);
  for (i = 1; i <= m; i++) printf("%I64d\n", ans[i]);
  return 0;
}