#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REPF(i, a, n) for (int i = a; i < (n); i++)
#define REP(i, n) REPF(i, 0, n)
#define FORE(x, s) for (auto& x : s)
#define ALL(x) begin(x),end(x)

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> g(N);
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<bool> oncycle(N, false), vis(N, false);
    vector<int> parent(N, -1), depth(N, 0);
    int x, y;
    function<void(int, int)> dfs = [&](int v, int p) {
        vis[v] = true;
        parent[v] = p;
        if (p != -1) depth[v] = depth[p] + 1;
        FORE(w, g[v]) {
            if (w == p) continue;
            if (vis[w]) {
                x = v, y = w;
                return;
            } else {
                dfs(w, v);
            }
        }
    };
    dfs(0, -1);
    
    {
        oncycle[x] = oncycle[y] = true;
        while (depth[x] > depth[y]) {
            x = parent[x];
            oncycle[x] = true;
        }
        while (depth[x] < depth[y]) {
            y = parent[y];
            oncycle[y] = true;
        }
        while (x != y) {
            x = parent[x];
            y = parent[y];
            oncycle[x] = oncycle[y] = true;
        }
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (oncycle[a] && oncycle[b]) {
            cout << 2 << endl;
        } else {
            cout << 1 << endl;
        }
    }
    return 0;
}
