//Linkwish's code #include #define endl '\n' #define si inline #define fi first #define se second using namespace std; typedef long long ll;typedef __int128 li;typedef long double ld; typedef pair pii;typedef pair pll; typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX; templatesi bool gmax(T &x,const T y){if(xsi bool gmin(T &x,const T y){if(y e[N]; int dfn[N],out[N],dep[N],sign; int son[N],sz[N],top[N],prv[N]; void dfs(int x,int fa){ sz[x]=1,dep[x]=dep[prv[x]=fa]+1; for(int to:e[x]){ if(to!=fa){ dfs(to,x),sz[x]+=sz[to]; if(!son[x]||sz[to]>sz[son[x]])son[x]=to; } } } void getdfn(int x,int fa){ dfn[x]=++sign; if(x==son[fa])top[x]=top[fa]; else top[x]=x; if(son[x])getdfn(son[x],x); for(int to:e[x])if(to!=fa&&to!=son[x])getdfn(to,x); out[x]=sign; } struct func{ int k,b; inline func(int x=1,int y=0){k=x,b=y;} inline void operator *= (func obj){k=1ll*k*obj.k%mod,b=(1ll*b*obj.k+obj.b)%mod;} }; struct Hoshino{ int ls,rs,l,r,L,R; func tag,v; }t[N]; int rt; si void update(int x,func v){t[x].tag*=v,t[x].v*=v;} si void push_down(int x){ if(t[x].tag.k!=1||t[x].tag.b!=0){ if(t[x].ls)update(t[x].ls,t[x].tag); if(t[x].rs)update(t[x].rs,t[x].tag); t[x].tag=func(); } } void build(int &x,int d,vector &p){ if(p.empty())return ; int s=p.size(); if(d)nth_element(p.begin(),p.begin()+(s-1)/2,p.end(),[&](int xx,int yy){return dep[xx] lp,rp; for(int i=0;i<(s-1)/2;i++)lp.push_back(p[i]); for(int i=(s-1)/2+1;ir||t[x].RR)return; if(t[x].l>=l&&t[x].r<=r&&t[x].L>=L&&t[x].R<=R)return update(x,k),void(); if(l<=dfn[x]&&r>=dfn[x]&&L<=dep[x]&&R>=dep[x])t[x].v*=k; push_down(x); modify(t[x].ls,l,r,L,R,k),modify(t[x].rs,l,r,L,R,k); } int ask(int x,int goal){ if(!x||t[x].l>dfn[goal]||t[x].rdep[goal]||t[x].Rdep[y])swap(x,y); modify(rt,dfn[x],dfn[y],1,n,k); } si void changeD(int x,int d,func k){ modify(rt,dfn[x],out[x],dep[x],dep[x]+d,k); for(int las=x,cur=prv[x];cur&&~(--d);las=cur,cur=prv[cur]){ modify(rt,dfn[cur],dfn[las]-1,dep[cur],dep[cur]+d,k); if(out[las]!=out[cur])modify(rt,out[las]+1,out[cur],dep[cur],dep[cur]+d,k); } } si int query(int x){ return ask(rt,x); } void mian(){ cin>>Case>>n>>m; for(int i=1,x,y;i>x>>y,e[x].push_back(y),e[y].push_back(x); for(int i=1;i<=n;i++)cin>>t[i].v.b; dfs(1,0),getdfn(1,0); vector tmp(n); iota(tmp.begin(),tmp.end(),1); build(rt,0,tmp); int op,x,y,k,b; while(m--){ cin>>op; if(op==1)cin>>x,cout<>x>>y>>k>>b,changeline(x,y,func(k,b)); else if(op==3)cin>>x>>k>>b,changesub(x,func(k,b)); else cin>>x>>y>>k>>b,changeD(x,y,func(k,b)); } } } signed main(){ #ifndef ONLINE_JUDGE assert(freopen("tour.in","r",stdin)); assert(freopen("tour.out","w",stdout)); #endif ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); LinkWish::mian(); return 0; }