#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 27;   vector<vector<int>> g;   int t, tin[N], tout[N], up[N][20], sz[N], d[N];   void dfs(int v, int p = 0, int dp = 0) {     tin[v] = t++;     d[v] = dp;     sz[v] = 1;     up[v][0] = p;     for (int i = 1; i < 20; i++) up[v][i] = up[up[v][i - 1]][i - 1];     for (int u : g[v]) {       if (u != p) {         dfs(u, v, dp + 1);         sz[v] += sz[u];       }     }     tout[v] = t++;   }   bool is(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }   int get_up(int a, int b) {     for (int i = 18; i >= 0; i--) {       if (!is(up[a][i], b)) a = up[a][i];     }     return a;   }   int lca(int a, int b) {     if (is(a, b)) return a;     if (is(b, a)) return b;     return up[get_up(a, b)][0];   }   int main() {     int n;     cin >> n;     g.resize(n + 1);     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     tin[0] = -1;     tout[0] = 3 * N;     dfs(1);     int q;     cin >> q;     for (int o = 0; o < q; o++) {       int a, b;       cin >> a >> b;       int l = lca(a, b);       if (a == b)         cout << n <<   n ;       else if (d[b] - d[l] == d[a] - d[l]) {         a = get_up(a, l);         b = get_up(b, l);         cout << n - sz[a] - sz[b] <<   n ;       } else {         if (d[a] < d[b]) swap(a, b);         int dist = d[a] + d[b] - 2 * d[l];         if (dist % 2) {           puts( 0 );           continue;         }         dist /= 2;         int u = a;         for (int i = 18; i >= 0; i--) {           if (d[a] - d[up[u][i]] < dist) u = up[u][i];         }         int m = up[u][0];         cout << sz[m] - sz[u] <<   n ;       }     }     return 0;   }   