#include using namespace std; #include using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++) using ll = long long; using P = pair; using Graph = vector>; using mint = modint998244353; #define INF 10000000 int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; Graph g(n, vector(n, INF)); rep(i, n-1) { int a, b; cin >> a >> b; a--; b--; g[a][b] = 1; g[b][a] = 1; } rep(i, n)g[i][i] = 0; rep(k, n) rep(i, n) rep(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]); rep(i, q){ int s, t; cin >> s >> t; s--; t--; int ans = 0; rep(j, n){ if(j==s || j==t)continue; if(g[j][s] == g[j][t] && g[j][s] !=INF && g[j][t] != INF)ans++; } cout << ans << "\n"; } }