/// vn.spoj.com/problems/LUBENICA/

/// hld+it by muoii

#include <bits/stdc++.h>
using namespace std;
#define tag "spoj"
#define maxn 100007
#define module 0
#define long long long
#define oo 1000000007
#define loop(x) for(int ruuun=0;ruuun<x;ruuun++)
///>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
int n,m;
vector<int> tour,go;
vector<int> id;
vector<int> W;
struct neigh{
    int ver,wei;
};
vector< vector<neigh> > adj;

struct nodeTree{
    int parent;
    int depth;
    int subsize;
    int chainTop;
};
vector<nodeTree> infor;
#define par(u) infor[u].parent
#define depth(u) infor[u].depth
#define subsize(u) infor[u].subsize
#define chainTop(u) infor[u].chainTop
#define jump(x) par(chainTop(x))

struct query{
    int emi,ema;
};
struct it{
    int n;
    vector<int> qmin,qmax;
    #define a(i) qmin[n+i-1]
    #define b(i) qmax[n+i-1]
    it() {};
    it(const int &sz,const vector<int> &a){
        n=sz;
        qmin.resize(2*n+2); qmax.resize(2*n+2);
        for(int i=1;i<=n;i++) a(i)=a[i],b(i)=a[i];
        build();
    }

    void build()
    {
        for(int i=n-1;i>=1;i--)
            qmin[i]=min(qmin[i<<1],qmin[i<<1|1]),
            qmax[i]=max(qmax[i<<1],qmax[i<<1|1]);
    }

    query get(int l,int r)
    {
        int emi=+oo,ema=-oo;
        for(l+=n-1,r+=n;l<r;l>>=1,r>>=1)
        {
            if(l&1) emi=min(emi,qmin[l]),ema=max(ema,qmax[l]),l++;
            if(r&1) --r,emi=min(emi,qmin[r]),ema=max(ema,qmax[r]);
        }
        return {emi,ema};
    }
} st;

void data()
{
    adj.resize(n+1);
    infor.resize(n+1);
    W.resize(n+1);
    id.resize(n+1);
    tour.resize(1);
}

///--------------
void dfs(const int &u,const int &parent,const int &depth)
{
    infor[u]={parent,depth,1};

    for(const auto &nei: adj[u])
        if(nei.ver!=parent)
            W[nei.ver]=nei.wei,dfs(nei.ver,u,depth+1),subsize(u)+=subsize(nei.ver);
}

void hld(const int &u,const int &parent,const int &top)
{
    id[u]=tour.size();
    tour.push_back(W[u]);
    go.push_back(u);
    chainTop(u)=top;

    int special=0;
    for(const auto &nei: adj[u])
        special=(nei.ver!=parent && subsize(nei.ver)>subsize(special))?nei.ver:special;

    if(special==0) return;

    hld(special,u,top);

    for(const auto &nei: adj[u])
        if(nei.ver!=parent && nei.ver!=special)
            hld(nei.ver,u,nei.ver);
}

void lca(int x,int y)
{
    query get;
    int emi=+oo,ema=-oo;
    while(chainTop(x)!=chainTop(y))
    if(depth(chainTop(x))>depth(chainTop(y)))
        {
            get=st.get(id[chainTop(x)],id[x]);
            emi=min(emi,get.emi);
            ema=max(ema,get.ema);

            x=jump(x);
        }
    else
        {
            get=st.get(id[chainTop(y)],id[y]);
            emi=min(emi,get.emi);
            ema=max(ema,get.ema);

            y=jump(y);
        }

    get=(depth(x)<depth(y))?st.get(id[x]+1,id[y]):st.get(id[y]+1,id[x]);

    emi=min(emi,get.emi);
    ema=max(ema,get.ema);

    cout<<emi<<" "<<ema<<"\n";
    return;
}

int main()
{
	#ifdef dmdd
    freopen(tag".inp","r",stdin); freopen(tag".out","w",stdout);
    #endif // dmdd
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin>>n;
    data();

    int u,v,w;
    loop(n-1) cin>>u>>v>>w,adj[u].push_back({v,w}),adj[v].push_back({u,w});

    ///tree&lcawithhld:
    dfs(1,0,1);
    hld(1,0,1);
    st=it(n,tour);

    cin>>m;
    while(m-->0) cin>>u>>v,lca(u,v);
    return 0;
}
