#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const Int DEBUG = 0;

struct HLDecomposition {
  Int n,pos;
  vector<vector<Int> > G;
  vector<Int> vid, head, sub, hvy, par, dep, inv, type;
  
  HLDecomposition(){}
  HLDecomposition(Int sz):
    n(sz),pos(0),G(n),
    vid(n,-1),head(n),sub(n,1),hvy(n,-1),
    par(n),dep(n),inv(n),type(n){}
  
  void add_edge(Int u, Int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void build(vector<Int> rs={0}) {
    Int c=0;
    for(Int r:rs){
      dfs(r);
      bfs(r, c++);
    }
  }
  
  void dfs(Int rt) {
    using T = pair<Int, Int>;
    stack<T> st;
    par[rt]=-1;
    dep[rt]=0;
    st.emplace(rt,0);
    while(!st.empty()){
      Int v=st.top().first;
      Int &i=st.top().second;
      if(i<(Int)G[v].size()){
	Int u=G[v][i++];
	if(u==par[v]) continue;
	par[u]=v;
	dep[u]=dep[v]+1;
	st.emplace(u,0);
      }else{
	st.pop();
	Int res=0;
	for(Int u:G[v]){
	  if(u==par[v]) continue;
	  sub[v]+=sub[u];
	  if(res<sub[u]) res=sub[u],hvy[v]=u;
	}
      }
    }
  }

  void bfs(Int r,Int c) {
    Int &k=pos;
    queue<Int> q({r});
    while(!q.empty()){
      Int h=q.front();q.pop();
      for(Int i=h;i!=-1;i=hvy[i]) {
	type[i]=c;
	vid[i]=k++;
	inv[vid[i]]=i;
	head[i]=h;
	for(Int j:G[i])
	  if(j!=par[i]&&j!=hvy[i]) q.push(j);
      }
    }
  }
  
  // for_each(vertex)
  // [l,r] <- attention!!
  void for_each(Int u, Int v, const function<void(Int, Int)>& f) {
    while(1){
      if(vid[u]>vid[v]) swap(u,v);
      f(max(vid[head[v]],vid[u]),vid[v]);
      if(head[u]!=head[v]) v=par[head[v]];
      else break;
    }
  }
  
  // for_each(edge)
  // [l,r] <- attention!!
  void for_each_edge(Int u, Int v, const function<void(Int, Int)>& f) {
    while(1){
      if(vid[u]>vid[v]) swap(u,v);
      if(head[u]!=head[v]){
	f(vid[head[v]],vid[v]);
        v=par[head[v]];
      } else{
	if(u!=v) f(vid[u]+1,vid[v]);
	break;
      }
    }
  }

  Int lca(Int u,Int v){
    while(1){
      if(vid[u]>vid[v]) swap(u,v);
      if(head[u]==head[v]) return u;
      v=par[head[v]];
    }
  }

  Int distance(Int u,Int v){
    return dep[u]+dep[v]-2*dep[lca(u,v)];
  }
};


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  Int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(Int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(Int)v.size()) build(n_,v);
  }
  void init(Int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(Int n_, vector<T> v){
    for(Int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(Int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(Int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  inline T query(Int a,Int b){
    T vl=d1,vr=d1;
    for(Int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[(l++)-1]);
      if(r&1) vr=f(dat[(--r)-1],vr);
    }
    return f(vl,vr);
  }

  Int find(Int a,Int b,function<bool(T)> &check,Int k,Int l,Int r){
    if(!check(dat[k])||r<=a||b<=l) return -1;
    if(k>=n-1) return k-(n-1);
    Int m=(l+r)>>1;
    Int vl=find(a,b,check,k*2+1,l,m);
    if(~vl) return vl;
    return find(a,b,check,k*2+2,m,r);
  }
  
  Int find(Int a,Int b,function<bool(T)> &check){
    return find(a,b,check,0,0,n);
  }
  
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> w(n);
  for(Int i=0;i<n;i++) cin>>w[i];
  HLDecomposition hld(n);
  for(Int i=1;i<n;i++){
    Int u,v;
    cin>>u>>v;
    u--;v--;
    hld.add_edge(u,v);
  }
  hld.build();
  auto G=hld.G;
  auto head=hld.head;
  auto vid=hld.vid;
  auto inv=hld.inv;
  
  vector<Int> dp(n),dp2(n,-1),dp3(n,-1);
  using P = pair<Int, Int>;
  vector<set<P> > ps(n);
  function<Int(Int,Int)> dfs=[&](Int v,Int p){
    dp[v]=w[v];
    ps[v].emplace(-1,-1);
    for(Int u:G[v]){
      if(u==p) continue;
      Int k=dfs(u,v);
      dp[v]+=k;
      if(head[v]!=head[u]){
	chmax(dp2[v],k);
	ps[v].emplace(k,u);
	if(DEBUG) cout<<v<<"->"<<u<<":"<<k<<endl;
      }else dp3[v]=k;
    }
    return dp[v];
  };
  dfs(0,-1);
  
  SegmentTree<Int, Int>::F f=[](Int a,Int b){return max(a,b);};
  SegmentTree<Int, Int>::G g=[](Int a,Int b){++a;return b;};
  SegmentTree<Int, Int> seg(n,f,g,-1);
  for(Int i=0;i<n;i++) seg.update(vid[i],dp2[i]);
  
  Int sum=accumulate(w.begin(),w.end(),Int(0));
  Int q;
  cin>>q;
  for(Int i=0;i<q;i++){
    Int u,v;
    cin>>u>>v;
    u--;v--;
    Int ans=sum-dp[hld.lca(u,v)];
    set<Int> s;
    hld.for_each(u,v,[&](Int l,Int r){
	if(l+1<r) chmax(ans,seg.query(l+1,r));
	if(DEBUG) cout<<inv[l]<<" "<<inv[r]<<endl;
	s.emplace(inv[l]);
	s.emplace(inv[r]);
	chmax(ans,dp3[inv[r]]);
      });
    if(DEBUG) cout<<ans<<endl;
    for(Int v:s){
      auto latte=--ps[v].end();
      while(s.count(latte->second)) --latte;
      if(DEBUG)  cout<<v<<" "<<latte->second<<":"<<latte->first<<endl;
      chmax(ans,latte->first);
    }
    cout<<ans<<endl;
  }
  
  
  return 0;
}



Measured memory_bytes: 46304