import math unit = (1,0,0,1) def mul(x, y): a = (x[0]*y[0]+x[1]*y[2])%(10**9+7) b = (x[0]*y[1]+x[1]*y[3])%(10**9+7) c = (x[2]*y[0]+x[3]*y[2])%(10**9+7) d = (x[2]*y[1]+x[3]*y[3])%(10**9+7) return (a,b,c,d) class Seg: def __init__(self, n): self.n = 2**math.ceil(math.log2(n)) self.data = [unit]*(self.n*2-1) def query(self, a, b): def _query(a, b, k, l, r): if b<=l or r<=a: return unit if a<=l and r<=b: return self.data[k] m = (l+r)//2 return mul(_query(a,b,k*2+1,l,m), _query(a,b,k*2+2,m,r)) return _query(a, b, 0, 0, self.n) def update(self, a, v): a += self.n-1 self.data[a] = v while a > 0: a = (a-1)//2 self.data[a] = mul(self.data[a*2+1], self.data[a*2+2]) n = int(input()) graph = [[] for _ in range(n)] for i in range(n-1): a, b = map(int, input().split()) graph[a].append((i,b)) graph[b].append((i,a)) edge = [0]*(n-1) parent = [0]*n bfs = [0] for u in bfs: for e, v in graph[u]: if v == parent[u]: continue parent[v] = u edge[e] = v bfs.append(v) size = [1]*n heavy = [0]*n for u in reversed(bfs): for _, v in graph[u]: if v != parent[u] and size[v]+1 > size[u]: size[u] = size[v]+1 heavy[u] = v chain = [] nxt = [] pos = [None]*n for u in bfs: if u == heavy[parent[u]]: i, j = pos[parent[u]] pos[u] = (i, j+1) else: pos[u] = (len(chain), 0) nxt.append(parent[u]) chain.append(Seg(size[u])) for _ in range(int(input())): typ, *rest = input().split() if typ == 'x': i, *x = map(int, rest) j, k = pos[edge[i]] chain[j].update(k, tuple(x)) else: i, j = map(int, rest) a, b = pos[j] c, d = pos[i] res = unit while a != c: res = mul(chain[a].query(0, b+1), res) a, b = pos[nxt[a]] print(*mul(chain[a].query(b+1, d+1), res))