#include <bits/stdc++.h>
using namespace std;

struct CycleDetection{
    vector<vector<int>> G;
    vector<int> seen,finished;
    stack<int> hist;
    int pos;
    CycleDetection(int n):G(n),seen(n,0),finished(n,0),pos(-1){}
    void add_edge(int u,int v){
        G[u].emplace_back(v);
    }
    void dfs(int v,int p){
        seen[v]=1; hist.push(v);
        for (int u:G[v]){
            if (u==p) continue;
            if (finished[u]) continue;
            if (seen[u]&&!finished[u]){pos=u; return;}
            dfs(u,v);
            if (pos!=-1) return;
        }
        finished[v]=1; hist.pop();
    }
    vector<int> build(int &cycle){
        dfs(0,-1);
        cycle=(pos!=-1);
        vector<int> res;
        while(!hist.empty()){
            int t=hist.top(); hist.pop();
            res.emplace_back(t);
            if (t==pos) break;
        }
        return res;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    CycleDetection CD(N);
    for (int i=0;i<N;++i){
        int u,v; cin >> u >> v; --u,--v;
        CD.add_edge(u,v); CD.add_edge(v,u);
    }
    int a;
    vector<int> Cycle=CD.build(a);
    set<int> s;
    for (int v:Cycle) s.emplace(v);
    int Q; cin >> Q;
    for (;Q--;){
        int a,b; cin >> a >> b;
        cout << (s.count(--a)&&s.count(--b)?2:1) << '\n';
    }
}
