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;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
int n, m, i, j, s[10000005], ans[10000005], a[100005], md[10000005],
    p[10000005], pc, fa[100005][19], mod = 1e9 + 7, inv[10000005], pk[100005],
                                     dep[100005];
vector<int> e[100005];
vector<pair<int, int> > seq[100005];
int pw(int x, int y) {
  int z = 1;
  while (y) {
    if (y & 1) {
      z = 1ll * z * x % mod;
    }
    x = 1ll * x * x % mod;
    y /= 2;
  }
  return z;
}
void dfs1(int x, int p) {
  fa[x][0] = p;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    if (*it == p) continue;
    dep[*it] = dep[x] + 1;
    dfs1(*it, x);
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int t = dep[x] - dep[y], i;
  for ((i) = (18); (i) >= (0); (i)--) {
    if ((t >> i) & 1) {
      x = fa[x][i];
    }
  }
  if (x == y) return x;
  for ((i) = (18); (i) >= (0); (i)--) {
    if (fa[x][i] != fa[y][i]) {
      x = fa[x][i];
      y = fa[y][i];
    }
  }
  return fa[x][0];
}
void inc(int x) {
  while (x != 1) {
    int t = md[x], j = 1;
    while (x % t == 0) {
      j = j * t;
      s[j] = 1ll * s[j] * t % mod;
      x /= t;
    }
  }
}
void dec(int x) {
  while (x != 1) {
    int t = md[x], j = 1;
    while (x % t == 0) {
      j = j * t;
      s[j] = 1ll * s[j] * inv[t] % mod;
      x /= t;
    }
  }
}
void qry(int x, int id, int op) {
  while (x != 1) {
    int t = md[x], j = 1;
    while (x % t == 0) {
      j = j * t;
      ans[id] = 1ll * ans[id] * (op ? s[j] : pw(s[j], mod - 2)) % mod;
      x /= t;
    }
  }
}
void dfs2(int x, int p) {
  inc(a[x]);
  for (__typeof((seq[x]).begin()) it = (seq[x]).begin(); it != (seq[x]).end();
       it++) {
    qry(pk[it->first], it->first, it->second);
  }
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    if (*it != p) dfs2(*it, x);
  }
  dec(a[x]);
}
int main() {
  inv[1] = 1;
  md[1] = 1;
  s[1] = 1;
  for (i = 2; i <= 10000000; i++) {
    s[i] = 1;
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
    if (!md[i]) {
      md[i] = i;
      p[++pc] = i;
    }
    for (j = 1; j <= pc; j++) {
      if (i * p[j] > 10000000) {
        break;
      }
      md[i * p[j]] = p[j];
      if (i % p[j] == 0) {
        break;
      }
    }
  }
  read(n);
  for (((i)) = (1); ((i)) <= ((n - 1)); ((i))++) {
    int x, y;
    read(x);
    read(y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    read(a[i]);
  }
  dfs1(1, 0);
  for (((j)) = (1); ((j)) <= ((18)); ((j))++) {
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
      fa[i][j] = fa[fa[i][j - 1]][j - 1];
    }
  }
  read(m);
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    int x, y, z;
    read(x);
    read(y);
    read(pk[i]);
    ans[i] = 1;
    z = lca(x, y);
    seq[x].push_back(make_pair(i, 1));
    seq[y].push_back(make_pair(i, 1));
    seq[z].push_back(make_pair(i, 0));
    seq[fa[z][0]].push_back(make_pair(i, 0));
  }
  dfs2(1, 0);
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}