#include<bits/stdc++.h>
#define int long long
#define ls (id<<1)
#define rs ((id<<1)|1)
using namespace std;
const int N=1e6+5;
int cnt=0,n,m,a[N],x,y,z,fa[N],son[N],sz[N],dep[N],top[N],dfn[N],mp[N],U,V,op;
vector<int> to[N];
void dfs1(int u,int F,int d) {
dep[u]=d,sz[u]++,fa[u]=F;
for(auto v:to[u]) {
if(v!=F) {
dfs1(v,u,d+1);
sz[u]+=sz[v];
if(sz[v]>sz[son[u]]) son[u]=v;
}
}
}
void dfs2(int u,int t) {
dfn[u]=++cnt,mp[cnt]=a[u],top[u]=t;
if(son[u]) dfs2(son[u],t);
for(auto v:to[u]) if(v!=fa[u]&&v!=son[u]) dfs2(v,v);
}
struct node {
int l,r,tag,sum,lma,rma,ma;
node(){
l=r=tag=sum=lma=rma=ma=0;
}
} t[N<<2];
void upd(int id,int x) {
t[id].tag=x;
t[id].sum=(t[id].r-t[id].l+1)*t[id].tag;
t[id].lma=t[id].rma=t[id].ma=t[id].sum;
}
void psd(int id) {
upd(ls,t[id].tag),upd(rs,t[id].tag);
t[id].tag=0;
}
void merge(node &a,node b,node c) {
a.sum=b.sum+c.sum;
a.lma=max(b.lma,c.ma+b.sum);
a.rma=max(c.rma,b.rma+c.sum);
a.ma=max(max(b.ma,c.ma),b.rma+c.lma);
a.tag=0;
}
void bld(int id,int l,int r) {
t[id].l=l,t[id].r=r;
if(l==r) {
t[id].sum=mp[l];
t[id].lma=t[id].rma=t[id].ma=t[id].sum;
return ;
}
int mid=(l+r)/2;
bld(ls,l,mid);
bld(rs,mid+1,r);
merge(t[id],t[ls],t[rs]);
}
void add(int id,int l,int r,int k) {
if(l<=t[id].l&&t[id].r<=r) {
upd(id,k);
return ;
}
if(t[id].tag) psd(id);
if(l<=t[ls].r) add(ls,l,r,k);
if(r>=t[rs].l) add(rs,l,r,k);
merge(t[id],t[ls],t[rs]);
}
node qry(int id,int l,int r) {
if(l<=t[id].l&&t[id].r<=r) return t[id];
if(t[id].tag) psd(id);
node res;
if(l>t[ls].r) return qry(rs,l,r);
if(r<t[rs].l) return qry(ls,l,r);
merge(res,qry(ls,l,r),qry(rs,l,r));
return res;
}
void Add1(int x,int y,int k) {
while(top[x]!=top[y]) {
if(dep[top[x]]<dep[top[y]]) swap(x,y);
add(1,dfn[top[x]],dfn[x],k);
x=fa[top[x]];
}
if(dep[x]>dep[y])swap(x,y);
add(1,dfn[x],dfn[y],k);
}
node Qry1(int x,int y) {
node t1,t2,ans;
while(top[x]!=top[y]){
if(dep[top[x]]<dep[top[y]]){
merge(t2,qry(1,dfn[top[y]],dfn[y]),t2);
y=fa[top[y]];
}else{
merge(t1,qry(1,dfn[top[x]],dfn[x]),t1);
x=fa[top[x]];
}
}
if(dep[x]>dep[y]) merge(t1,qry(1,dfn[y],dfn[x]),t1);
else merge(t2,qry(1,dfn[x],dfn[y]),t2);
swap(t1.lma,t1.rma);
merge(ans,t1,t2);
return ans;
}
signed main() {
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=1; i<n; i++) cin>>U>>V,to[U].push_back(V),to[V].push_back(U);
for(int i=1; i<=n; i++) reverse(to[i].begin(),to[i].end());
dfs1(1,0,1),dfs2(1,1),bld(1,1,n);
cin>>m;
for(int i=1; i<=m; i++) {
cin>>op;
if(op==1) cin>>x>>y,cout<<max(0ll,Qry1(x,y).ma)<<endl;
else cin>>x>>y>>z,Add1(x,y,z);
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbG9uZyBsb25nCiNkZWZpbmUgbHMgKGlkPDwxKQojZGVmaW5lIHJzICgoaWQ8PDEpfDEpCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOPTFlNis1OwppbnQgY250PTAsbixtLGFbTl0seCx5LHosZmFbTl0sc29uW05dLHN6W05dLGRlcFtOXSx0b3BbTl0sZGZuW05dLG1wW05dLFUsVixvcDsKdmVjdG9yPGludD4gdG9bTl07CnZvaWQgZGZzMShpbnQg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