#include<cstdio>
#include<algorithm>
using namespace std;
struct node {
int to,dis,next;
};
struct node edge[50000*2+1];
int n,m,head[50001],num=0,dfn[50001],flag=0;
char ch;
inline void read_int(int &x)
{
x=0;ch=getchar();
while(ch>‘9‘||ch<‘0‘) ch=getchar();
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+(int)(ch-‘0‘);ch=getchar();}
}
inline void edge_add(int from,int to,int dis)
{
num++;
edge[num].to=to;
edge[num].dis=dis;
edge[num].next=head[from];
head[from]=num;
}
void dfs(int now)
{
dfn[now]=++flag;
for(int i=head[now];i;i=edge[i].next) if(!dfn[edge[i].to]) dfs(edge[i].to);
}
int lca(int now_1,int now_2)
{
int dis_1=0,dis_2=0;
while(dfn[now_2]>dfn[now_1])
{
for(int i=head[now_2];i;i=edge[i].next)
{
if(dfn[edge[i].to]<dfn[now_2])
{
now_2=edge[i].to;
dis_2+=edge[i].dis;
}
}
}
while(dfn[now_1]>dfn[now_2])
{
for(int i=head[now_1];i;i=edge[i].next)
{
if(dfn[edge[i].to]<dfn[now_1])
{
now_1=edge[i].to;
dis_1+=edge[i].dis;
}
}
}
return dis_1+dis_2;
}
int main()
{
read_int(n);
int from,to,dis;
for(int i=1;i<n;i++)
{
read_int(from),read_int(to),read_int(dis);
edge_add(from,to,dis);
edge_add(to,from,dis);
}
read_int(m);
dfs(1);
for(int i=1;i<=m;i++)
{
read_int(from),read_int(to);
if(dfn[from]>dfn[to]) swap(from,to);
printf("%d\n",lca(from,to));
}
return 0;
}