#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a rank; vector> d; LCA(vector>& g, int root = 0){ init(g, root); } void init(vector>& g, int root = 0){ _n = g.size(), _log = 0; while((1<<_log)<=_n) _log++; rank = vector(_n); rank[root] = 0; d = vector>(_n, vector(_log)); dfs(-1,root,g); for(int j=0;j<_log-1;j++){ for(int i=0;i<_n;i++){ if(d[i][j]>=0) d[i][j+1] = d[d[i][j]][j]; else d[i][j+1] = -1; } } } void dfs(int par, int now, vector>& g){ d[now][0] = par; for(int x:g[now]){ if(x==par) continue; rank[x] = rank[now]+1; dfs(now,x,g); } } int prev(int u, int x){ assert(x>=0); for(int i=0;i<_log;i++){ if(x&1) u = d[u][i]; x >>= 1; if(!x || u<0) return u; } return -1; } int lca(int u, int v){ if(rank[u]>rank[v]) swap(u,v); v = prev(v, rank[v]-rank[u]); for(int i=_log-1;i>=0;i--){ if(d[u][i]!=d[v][i]) u = d[u][i], v = d[v][i]; } if(u!=v) return d[u][0]; return u; } int dist(int u, int v){ return rank[u] + rank[v] - 2*rank[lca(u,v)]; } }; vector st; void dfs(int par, int now, vector>& g){ for(int x:g[now]){ if(x==par) continue; dfs(now,x,g); st[now] += st[x]; } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,q; cin >> n >> q; vector> g(n); rep(i,n-1){ int u,v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } st = vector(n,1); dfs(-1,0,g); LCA l(g); rep(houren,q){ int s,t,ans; cin >> s >> t; s--; t--; int d = l.dist(s,t); if(d&1) ans = 0; else{ if(l.rank[s]==l.rank[t]){ s = l.prev(s,d/2-1); t = l.prev(t,d/2-1); ans = n - st[s] - st[t]; }else{ if(l.rank[s]>l.rank[t]) swap(s,t); s = l.prev(t,d/2-1); t = l.prev(t,d/2); ans = st[t] - st[s]; } } cout << ans << '\n'; } return 0; }