#include using namespace std; const int LOG = 17; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector> E(N); for (int i = 0; i < N - 1; i++){ int A, B; cin >> A >> B; A--; B--; E[A].push_back(B); E[B].push_back(A); } 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]; } } vector> pp(LOG, vector(N, -1)); pp[0] = p; for (int i = 0; i < LOG - 1; i++){ for (int j = 0; j < N; j++){ if (pp[i][j] != -1){ pp[i + 1][j] = pp[i][pp[i][j]]; } } } auto la = [&](int v, int x){ for (int i = 0; i < LOG; i++){ if ((x >> i & 1) == 1){ v = pp[i][v]; } } return v; }; auto lca = [&](int u, int v){ if (d[u] > d[v]){ swap(u, v); } v = la(v, d[v] - d[u]); if (u == v){ return u; } for (int i = LOG - 1; i >= 0; i--){ if (pp[i][u] != pp[i][v]){ u = pp[i][u]; v = pp[i][v]; } } return pp[0][u]; }; for (int i = 0; i < Q; i++){ int S, T; cin >> S >> T; S--; T--; if (d[S] > d[T]){ swap(S, T); } if (d[S] % 2 != d[T] % 2){ cout << 0 << '\n'; } else { int V = lca(S, T); if (d[S] == d[T]){ int s = la(S, d[S] - d[V] - 1); int t = la(T, d[T] - d[V] - 1); cout << N - dp[s] - dp[t] << '\n'; } else { int D = d[S] + d[T] - d[V] * 2; int s = la(T, D / 2); int t = la(T, D / 2 - 1); cout << dp[s] - dp[t] << '\n'; } } } }