#include using namespace std; int main(){ int N, Q; cin >> N >> Q; vector> E(N); for (int i = 0; i < N - 1; i++){ int U, V; cin >> U >> V; U--; V--; E[U].push_back(V); E[V].push_back(U); } vector p(N, -1); vector> c(N); vector d(N, 0); queue q; q.push(0); vector bfs; while (!q.empty()){ int v = q.front(); q.pop(); bfs.push_back(v); for (int w : E[v]){ if (w != p[v]){ p[w] = v; c[v].push_back(w); d[w] = d[v] + 1; q.push(w); } } } reverse(bfs.begin(), bfs.end()); vector dp(N, 1); for (int v : bfs){ for (int w : c[v]){ dp[v] += dp[w]; } } auto naive_lca = [&](int u, int v){ while (d[u] > d[v]){ u = p[u]; } while (d[v] > d[u]){ v = p[v]; } while (u != v){ u = p[u]; v = p[v]; } return u; }; auto naive_la = [&](int v, int k){ for (int i = 0; i < k; i++){ v = p[v]; } return v; }; for (int i = 0; i < Q; i++){ int A, B; cin >> A >> B; A--; B--; if (d[A] > d[B]){ swap(A, B); } if (d[A] % 2 != d[B] % 2){ cout << 0 << endl; } else { int C = naive_lca(A, B); if (d[A] == d[B]){ int A2 = naive_la(A, d[A] - d[C] - 1); int B2 = naive_la(B, d[B] - d[C] - 1); cout << N - dp[A2] - dp[B2] << endl; } else { int D = d[A] + d[B] - d[C] * 2; int X = naive_la(B, D / 2); int Y = naive_la(B, D / 2 - 1); cout << dp[X] - dp[Y] << endl; } } } }