#include <bits/stdc++.h>

using namespace std;
const int nmax = 100005;
int n, m, din;
int dad[nmax], dd[nmax], h[nmax], inT[nmax], outT[nmax];
vector <int> adj[nmax];
struct query
{
    int u,v;
} q[nmax];
void input()
{
    freopen("GUIDE.INP", "r", stdin);
    freopen("GUIDE.OUT", "w", stdout);
    scanf("%d", &n);
    for (int i=1; i<=n-1; i++)
    {
        int u,v ;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    scanf("%d", &m);
    for (int i=1; i<=m; i++) scanf("%d%d", &q[i].u, &q[i].v);
}

void DFS(int u)
{
    dd[u] = 1;
    inT[u] = ++din;
    for (int i=0; i<adj[u].size(); i++)
    {
        int v = adj[u][i];
        if (dd[v] == 0)
        {
            dad[v] = u;
            h[v] = h[u] + 1;
            DFS(v);
        }
    }
    outT[u] = ++din;
}

int _find(int u, int v)
{
    for (int i=0; i<adj[u].size(); i++)
    {
        int k = adj[u][i];
        if (k != dad[u])
        if (inT[k] < inT[v] && inT[v] < outT[v] && outT[v] < outT[k]) return k;
    }
}
void process()
{
    for (int i=1; i<=m; i++)
    {
        int u = q[i].u;
        int v = q[i].v;
        if (inT[u] < inT[v] && inT[v] < outT[v] && outT[v] < outT[u])
        {
            if (u == dad[v]) printf("%d", v);
            else printf("%d",_find(u,v));
        }
        else printf("%d", dad[u]);
        printf("\n");
    }
}
int main()
{
    input();
    DFS(1);
    process();
    return 0;
}
