#include <cstdio>
#include <vector>
int a[50001] = { 0, }, d[50001];
std::vector<std::pair<int, int>> temp;
int find(int x, int y) {
while (d[x]>d[y]) x = a[x];
while (d[x]<d[y]) y = a[y];
while (x != y)
{
x = a[x];
y = a[y];
}
return x;
}
int main() {
int n;
scanf("%d", &n);
a[1] = -1, d[1] = 0;
for (int i = 1; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
if (a[x] == 0 && a[y] == 0)
temp.push_back(std::pair<int, int>(x, y));
else if (a[x] == 0) {
a[x] = y;
d[x] = d[y] + 1;
}
else {
a[y] = x;
d[y] = d[x] + 1;
}
}
while (!temp.empty()) {
for (int i = 0; i < temp.size(); i++) {
int x = temp[i].first, y = temp[i].second;
if (a[y] != 0) {
a[x] = y;
d[x] = d[y] + 1;
temp.erase(temp.begin() + i);
i--;
}
else if (a[x] != 0) {
a[y] = x;
d[y] = d[x] + 1;
temp.erase(temp.begin() + i);
i--;
}
}
}
int m;
scanf("%d", &m);
for (int i = 0; i < m; i++) {
int t1, t2;
scanf("%d %d", &t1, &t2);
printf("%d\n", find(t1, t2));
}
return 0;
}