using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Myon
{
public Myon() { }
public static int Main()
{
new Myon().calc();
return 0;
}
int N;
int[] x, y;
List<int>[] es;
int[] parent;
int[,] dp;
int[] depth;
int MAX = 20;
void calc()
{
Scanner cin = new Scanner();
N = cin.nextInt();
x = new int[N];
y = new int[N];
for (int i = 0; i < N - 1; i++)
{
x[i] = cin.nextInt() - 1;
y[i] = cin.nextInt() - 1;
}
//辺を全てリストに入れる
es = new List<int>[N];
for (int i = 0; i < N; i++)
{
es[i] = new List<int>();
}
for (int i = 0; i < N; i++)
{
es[x[i]].Add(y[i]);
es[y[i]].Add(x[i]);
}
//親、1,2,4,8...個上、自分の深さの情報を
//dfsで求める
parent = new int[N];
dp = new int[N, MAX];
depth = new int[N];
dfs(0, -1, 0);
//ここからクエリごとの処理
int Q = cin.nextInt();
for (int i = 0; i < Q; i++)
{
int a = cin.nextInt() - 1;
int b = cin.nextInt() - 1;
//高さを揃える
int ret = 0;
if (depth[a] > depth[b])
{
swap(ref a, ref b);
}
if (depth[a] < depth[b])
{
ret = depth[b] - depth[a];
b = getV(b, ret);
}
//一致しないぎりぎりのところまで登って行く
//16, 8, 4, 2, 1個上・・・・って順番で見ていけば
//一致しないぎりぎりのところが求められる
for (int j = MAX - 1; j >= 0; j--)
{
if (dp[a, j] == dp[b, j]) continue;
else
{
a = dp[a, j];
b = dp[b, j];
ret += 2 * (1 << j);
}
}
//高さを揃えた時点で、一致しているケースは
//すでに一致しているので足す必要はないが、
//一致していないケースは、それぞれ1個上る必要がある
//そこで、ret に2を足してあげる
if (a != b) ret += 2;
//最後に、追加される1つの辺が閉路に加わるので
//1を足してあげる
ret += 1;
Console.WriteLine(ret);
}
}
//swap
void swap<T>(ref T a, ref T b)
{
T c = a;
a = b;
b = c;
}
int getV(int a, int dep)
{
int now = a;
//頂点aのdep個上の値を得る
for (int i = 0; (1 << i) <= dep; i++)
{
if ((dep >> i) % 2 == 1)
{
now = dp[now, i];
//dp[a, b] っていうのは、aの2^b個上を見れる。
}
}
return now;
}
void dfs(int a, int pre, int dep)
{
depth[a] = dep;
parent[a] = pre;
dp[a, 0] = pre;
//ダブリングを用いて、1,2,4,8個上を決めていく
for (int i = 1; i < MAX; i++)
{
if (dp[a, i - 1] != -1) dp[a, i] = dp[dp[a, i - 1], i - 1];
else dp[a, i] = -1;
}
//次の頂点を探す
foreach (var item in es[a])
{
if (item == pre) continue;
dfs(item, a, dep + 1);
}
}
}
class Scanner
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner()
{
s = new string[0];
i = 0;
}
public string next()
{
if (i < s.Length) return s[i++];
do
{
s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
} while ((s.Length == 1 && s[0] == "") || s.Length == 0);
i = 0;
return s[i++];
}
public int nextInt()
{
return int.Parse(next());
}
public long nextLong()
{
return long.Parse(next());
}
public double nextDouble()
{
return double.Parse(next());
}
}