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 N = 100005;
struct edge {
  int to, next;
} e[N * 2];
int head[N], tot;
void add(int x, int y) {
  e[++tot] = (edge){y, head[x]};
  head[x] = tot;
}
int dep[N], fa[N][20];
void dfs(int x) {
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa[x][0]) {
      fa[e[i].to][0] = x;
      dep[e[i].to] = dep[x] + 1;
      dfs(e[i].to);
    }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int tmp = dep[x] - dep[y];
  for (int i = 18; i >= 0; i--)
    if (tmp & (1 << i)) x = fa[x][i];
  for (int i = 18; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return (x == y ? x : fa[x][0]);
}
const int M = 10000005;
bool fl[M];
int mn[M], pri[666666], cnt;
void divide(vector<pair<int, int> > &a, int v) {
  a.resize(0);
  for (; v != 1;) {
    int cnt = 0, id = mn[v], lav = pri[id];
    for (; v % lav == 0; v /= lav, cnt++)
      ;
    a.push_back(pair<int, int>(id, cnt));
  }
}
vector<pair<int, int> > vec[N], tmp;
struct que {
  int type, id, first, second;
};
vector<que> q[N];
int tong[666666][30];
const int mo = 1000000007;
int power(int x, int y) {
  int s = 1;
  for (; y; y /= 2, x = 1ll * x * x % mo)
    if (y & 1) s = 1ll * s * x % mo;
  return s;
}
int ans[N];
void work(int x) {
  for (int i = 0; i < vec[x].size(); i++)
    tong[vec[x][i].first][vec[x][i].second]++;
  for (int i = 0; i < q[x].size(); i++) {
    int sum = 0;
    for (int j = 0; j <= 28; j++)
      if (tong[q[x][i].first][j])
        sum += tong[q[x][i].first][j] * min(q[x][i].second, j);
    int tmp = power(pri[q[x][i].first], sum) % mo;
    if (q[x][i].type == -1) tmp = power(tmp, mo - 2);
    ans[q[x][i].id] = 1ll * ans[q[x][i].id] * tmp % mo;
  }
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa[x][0]) work(e[i].to);
  for (int i = 0; i < vec[x].size(); i++)
    tong[vec[x][i].first][vec[x][i].second]--;
}
int n, Q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  for (int i = 2; i < M; i++)
    if (!fl[i]) {
      pri[++cnt] = i;
      mn[i] = cnt;
      for (int j = i + i; j < M; j += i) {
        fl[j] = 1;
        if (!mn[j]) mn[j] = cnt;
      }
    }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    divide(vec[i], x);
  }
  dfs(1);
  for (int i = 1; i <= 18; i++)
    for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int x, y, v, L;
    scanf("%d%d%d", &x, &y, &v);
    divide(tmp, v);
    L = lca(x, y);
    for (int j = 0; j < tmp.size(); j++) {
      q[x].push_back((que){1, i, tmp[j].first, tmp[j].second});
      q[y].push_back((que){1, i, tmp[j].first, tmp[j].second});
      q[L].push_back((que){-1, i, tmp[j].first, tmp[j].second});
      q[fa[L][0]].push_back((que){-1, i, tmp[j].first, tmp[j].second});
    }
    ans[i] = 1;
  }
  work(1);
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
}