from sys import stdin input=lambda :stdin.readline()[:-1] class lazy_segtree(): def update(self,k):self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def all_apply(self,k,f): self.d[k]=self.mapping(f,self.d[k]) if (k>i) self.d[p]=x for i in range(1,self.log+1):self.update(p>>i) def get(self,p): assert 0<=p and p>i) return self.d[p] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n if l==r:return self.e l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<>i) if (((r>>i)<>i) sml,smr=self.e,self.e while(l>=1 r>>=1 return self.op(sml,smr) def all_prod(self):return self.d[1] def apply_point(self,p,f): assert 0<=p and p>i) self.d[p]=self.mapping(f,self.d[p]) for i in range(1,self.log+1):self.update(p>>i) def apply(self,l,r,f): assert 0<=l and l<=r and r<=self.n if l==r:return l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<>i) if (((r>>i)<>i) l2,r2=l,r while(l>=1 r>>=1 l,r=l2,r2 for i in range(1,self.log+1): if (((l>>i)<>i) if (((r>>i)<>i) def max_right(self,l,g): assert 0<=l and l<=self.n assert g(self.e) if l==self.n:return self.n l+=self.size for i in range(self.log,0,-1):self.push(l>>i) sm=self.e while(1): while(l%2==0):l>>=1 if not(g(self.op(sm,self.d[l]))): while(l>i) sm=self.e while(1): r-=1 while(r>1 and (r%2)):r>>=1 if not(g(self.op(self.d[r],sm))): while(r>20 a1=a&mask b0=b>>20 b1=b&mask return ((a0+b0)<<20)+a1+b1 e=0 def mapping(f,x): x0=x>>20 x1=x&mask return ((x0+f*x1)<<20)+x1 def composition(f,g): return f+g id=0 class HeavyLightDecomposition: def __init__(self,n,edge): self.n=n self.sub_size=[1]*n self.par=[-1]*n todo=[0] while todo: v=todo.pop() if v>=0: for u in edge[v]: if u!=self.par[v]: todo.append(~u) todo.append(u) self.par[u]=v else: v=~v self.sub_size[self.par[v]]+=self.sub_size[v] self.head=[-1]*n self.head[0]=0 self.order=[-1]*n self.heavy_child=[-1]*n todo=[0] cnt=0 while todo: v=todo.pop() self.order[v]=cnt cnt+=1 mx=0 for u in edge[v]: if u!=self.par[v] and mxself.order[v]: u,v=v,u if self.head[u]!=self.head[v]: paths.append((self.order[self.head[v]],self.order[v]+1)) v=self.par[self.head[v]] else: paths.append((self.order[u]+1,self.order[v]+1)) return paths def for_each_vertex(self,u,v): paths=[] while True: if self.order[u]>self.order[v]: u,v=v,u if self.head[u]!=self.head[v]: paths.append((self.order[self.head[v]],self.order[v]+1)) v=self.par[self.head[v]] else: paths.append((self.order[u],self.order[v]+1)) return paths n=int(input()) edge=[[] for i in range(n)] for _ in range(n-1): a,b=map(lambda x:int(x)-1,input().split()) edge[a].append(b) edge[b].append(a) HLD=HeavyLightDecomposition(n,edge) seg=lazy_segtree([(1<<20)+1 for i in range(n)],op,e,mapping,composition,id) ans=0 q=int(input()) for _ in range(q): x,y=map(lambda x:int(x)-1,input().split()) for l,r in HLD.for_each_vertex(x,y): ans+=seg.prod(l,r)>>20 seg.apply(l,r,1) print(ans)