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 double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 3.1e5;
const int MAXLOG = 20;
vector<int> adj[MAXN];
int centroid_parent[MAXN];
int centroid_depth[MAXN];
int centroid_subsize[MAXN];
int centroid_maxremaining[MAXN];
int centroid_rek(int n, int p) {
  if (centroid_depth[n] != -1) return centroid_subsize[n] = 0;
  int res = 1;
  for (auto it : adj[n])
    if (it != p) res += centroid_rek(it, n);
  return centroid_subsize[n] = res;
}
void centroid_rek2(int& c, int n, int p, int S) {
  if (centroid_depth[n] != -1) return;
  int cur = 0;
  int rem = S - 1;
  for (auto it : adj[n])
    if (it != p) {
      cur = max(cur, centroid_subsize[it]);
      rem -= centroid_subsize[it];
    }
  cur = max(cur, rem);
  centroid_maxremaining[n] = cur;
  if (centroid_maxremaining[n] < centroid_maxremaining[c]) {
    c = n;
  }
  for (auto it : adj[n])
    if (it != p) centroid_rek2(c, it, n, S);
}
void centroid_decomposition(int n, int depth, int c_par) {
  assert(centroid_depth[n] == -1);
  int S = centroid_rek(n, -1);
  int c = n;
  centroid_maxremaining[c] = S;
  centroid_rek2(c, n, -1, S);
  centroid_depth[c] = depth;
  centroid_parent[c] = c_par;
  for (auto it : adj[c])
    if (centroid_depth[it] == -1) centroid_decomposition(it, depth + 1, c);
}
int node_value[MAXN];
int query_res[MAXN];
int query_from_to[MAXN][2];
int query_value[MAXN];
vector<int> responsible[MAXN];
vector<int> todo[MAXN];
const int MAXNUM = 1e7 + 10;
int smallest_div[MAXNUM];
int cur_count[MAXNUM];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long pow_mod(long long v, int p) {
  if (p == 0) return 1;
  long long res = pow_mod((v * v) % MOD, p / 2);
  if (p & 1) res = (res * v) % MOD;
  return res;
}
long long inverse(long long v) { return pow_mod(v, MOD - 2); }
void query_rek(int n, int min_depth, int par) {
  if (centroid_depth[n] < min_depth) return;
  int f = node_value[n];
  while (f != 1) {
    int p = smallest_div[f];
    int pp = 1;
    while (f % p == 0) {
      pp *= p;
      f /= p;
      ++cur_count[pp];
    }
  }
  for (auto q : todo[n]) {
    f = query_value[q];
    while (f != 1) {
      int p = smallest_div[f];
      int pp = 1;
      while (f % p == 0) {
        pp *= p;
        f /= p;
        query_res[q] = (query_res[q] * pow_mod(p, cur_count[pp])) % MOD;
      }
    }
  }
  todo[n].clear();
  for (auto to : adj[n])
    if (to != par) {
      query_rek(to, min_depth, n);
    }
  f = node_value[n];
  while (f != 1) {
    int p = smallest_div[f];
    int pp = 1;
    while (f % p == 0) {
      pp *= p;
      f /= p;
      --cur_count[pp];
    }
  }
}
void calc() {
  for (int i = (0); i < (MAXNUM); i++) cur_count[i] = 0;
  for (int i = (0); i < (MAXNUM); i++) smallest_div[i] = i;
  for (int i = (2); i < (MAXNUM); i++)
    if (smallest_div[i] == i) {
      for (int j = (i); j < (oo); j++) {
        if ((MAXNUM - 1) / i < j) break;
        smallest_div[j * i] = min(smallest_div[j * i], i);
      }
    }
  int N;
  if (0 == scanf("%d", &N)) {
    fprintf(stderr, "Could not parse arguments\n");
  };
  for (int i = (0); i < (N + 1); i++) adj[i].clear();
  for (int i = (1); i < (N); i++) {
    int a, b;
    if (0 == scanf("%d%d", &a, &b)) {
      fprintf(stderr, "Could not parse arguments\n");
    };
    adj[b].push_back(a);
    adj[a].push_back(b);
  }
  for (int i = (0); i < (N + 1); i++) centroid_depth[i] = -1;
  centroid_decomposition(1, 0, -1);
  for (int i = (1); i < (N + 1); i++)
    if (0 == scanf("%d", node_value + i)) {
      fprintf(stderr, "Could not parse arguments\n");
    };
  for (int i = (1); i < (N + 1); i++) responsible[i].clear();
  int Q;
  if (0 == scanf("%d", &Q)) {
    fprintf(stderr, "Could not parse arguments\n");
  };
  for (int q = (0); q < (Q); q++) {
    query_res[q] = 1;
    for (int j = (0); j < (2); j++)
      if (0 == scanf("%d", &(query_from_to[q][j]))) {
        fprintf(stderr, "Could not parse arguments\n");
      };
    if (0 == scanf("%d", query_value + q)) {
      fprintf(stderr, "Could not parse arguments\n");
    };
    int a = query_from_to[q][0];
    int b = query_from_to[q][1];
    if (centroid_depth[a] > centroid_depth[b]) swap(a, b);
    while (centroid_depth[b] > centroid_depth[a]) b = centroid_parent[b];
    while (a != b) {
      a = centroid_parent[a];
      b = centroid_parent[b];
    }
    responsible[a].push_back(q);
  }
  for (int i = (1); i < (N + 1); i++) todo[i].clear();
  for (int n = (1); n < (N + 1); n++) {
    for (auto q : responsible[n]) {
      for (int i = (0); i < (2); i++) todo[query_from_to[q][i]].push_back(q);
      long long v = gcd(query_value[q], node_value[n]);
      query_res[q] = inverse(v);
    }
    query_rek(n, centroid_depth[n], -1);
  }
  for (int q = (0); q < (Q); q++) {
    cout << query_res[q] << endl;
  }
}
int main() {
  calc();
  return 0;
}