#include using namespace std; using ll = long long; //const ll mod = 998'244'353; const ll mod = 1'000'000'007; //const ll mod = 67'280'421'310'721; struct mint{ long long x; mint(long long x=0):x((x%mod+mod)%mod){} mint operator-() const{ return mint(-x); } mint& operator+=(const mint& a){ if((x+=a.x)>=mod)x-=mod; return *this; } mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod)x-=mod; return *this; } mint& operator*=(const mint& a){ (x *= a.x) %= mod; return *this; } mint operator+(const mint& a) const{ mint res(*this); return res+=a; } mint operator-(const mint& a) const{ mint res(*this); return res-=a; } mint operator*(const mint& a) const{ mint res(*this); return res*=a; } mint pow(long long n) const { assert(0 <= n); mint a = *this, r = 1; while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; } mint inv() const{ return pow(mod-2); } mint& operator/=(const mint& a){ return (*this)*=a.inv(); } mint operator/(const mint& a) const { mint res(*this); return res/=a; } friend ostream& operator<<(ostream& os, const mint& m){ os << m.x; return os; } bool operator==(const mint& a) const { return x == a.x; } bool operator<(const mint& a) const{ return x < a.x; } }; template< typename T1, typename T2 = T1 > struct lazysegtree{ using F1 = function; using F2 = function; //using F3 = function; using F3 = function; int n; F1 f1; F2 f2; F3 f3; T1 e1; T2 e2,e3; vector data; vector lazy;//莨晄成繝・・繧ソ vector p;//莨晄成縺ョ繝輔Λ繧ーW /* * n:鬆らせ謨ー * f1:隕∫エ蜷悟」ォ縺ョ貍皮ョ・f2:菴懃畑邏蜷悟」ォ,f3:菴懃畑 * e:蜊倅ス榊・ */ lazysegtree(int _n,F1 f1,F2 f2,F3 f3,T1 e1,T2 e2,T2 e3):f1(f1),f2(f2),f3(f3),e1(e1),e2(e2),e3(e3){ n = 1; while(n<_n) n<<=1; data.assign(2*n,e1); lazy.assign(2*n,e3); p.assign(2*n,0); } void set(int i,T1 x){ data[i+n-1] = x; } void build(){ for(int i = n - 2;i>=0;i--){ data[i] = f1(data[2*i+1],data[2*i+2]); } } void rangeupdate(T2 x,int a,int b,int ni,int l,int r){ update(ni,l,r); if(b<=l||r<=a) return; if(a<=l&&r<=b){ p[ni] = 1; lazy[ni] = f2(x,lazy[ni]); update(ni,l,r); }else{ rangeupdate(x,a,b,2*ni+1,l,(l+r)/2); rangeupdate(x,a,b,2*ni+2,(l+r)/2,r); if(l+1 g[mx]; int n; pair c1(pair a,pair b){ a.first += b.first; a.second += b.second; return a; } mint c2(mint a,mint b){ return a + b; } pair c3(mint a,pair b,ll l,ll r){ b.first += a * b.second; return b; } int sdfs(int ni,int p){ sz[ni] = 1; par[ni] = p; if(g[ni].size()&&g[ni][0]==p) swap(g[ni][0],g[ni].back()); for(auto&to:g[ni]){ if(to==p) continue; sz[ni] += sdfs(to,ni); if(sz[to]>sz[g[ni][0]]) swap(to,g[ni][0]); } return sz[ni]; } void hdfs(int ni,int p,int&time){ in[ni] = time++; for(auto&to:g[ni]){ if(to==p) continue; head[to] = (g[ni][0]==to?head[ni]:to); hdfs(to,ni,time); } out[ni] = time; } int main(){ cin>>n; vector s(n),c(n); for(int i = 0;i>x; s[i] = mint(x); } for(int i = 0;i>x; c[i] = mint(x); } for(int i = 1;i>u>>v; u--;v--; g[u].push_back(v); g[v].push_back(u); } lazysegtree,mint> seg(n,c1,c2,c3,make_pair(mint(0),mint(0)),mint(0),mint(0)); sdfs(0,-1); int time = 0; hdfs(0,-1,time); for(int i = 0;i>q; seg.build(); while(q--){ int t; cin>>t; if(t==0){ int u,v;ll z; cin>>u>>v>>z; u--;v--; for(;;v=par[head[v]]){ if(in[u]>in[v]) swap(u,v); if(head[u]==head[v]) break; seg.rangeupdate(mint(z),in[head[v]],in[v]+1); } seg.rangeupdate(mint(z),in[u],in[v]+1); }else{ mint ans = 0; int u,v; cin>>u>>v; u--;v--; //cout<in[v]) swap(u,v); if(head[u]==head[v]) break; auto itr = seg.query(in[head[v]],in[v]+1); ans += itr.first; //cout<