#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

struct Edge{int to,weight; Edge(int t, int w) : to(t), weight(w) {}};
using DirectedGraph = vector<vector<Edge>>;
using UndirectedGraph = vector<vector<int>>;

vector<bool> seen,finished;
int pos = -1;
stack<int> hist;

void dfs(const UndirectedGraph &G,int v,int p){
    seen[v] = true;
    hist.push(v);
    for(auto nv:G[v]){
        if(nv==p) continue;
        if(finished[nv]) continue;
        if(seen[nv] && !finished[nv]){
            pos = nv;
            return;
        }

        dfs(G,nv,v);
        if(pos != -1) return;
    }
    hist.pop();
    finished[v] = true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;cin>>N;

    UndirectedGraph G(N);
    REP(i,N){
        int a,b;
        cin>>a>>b;
        --a,--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen.assign(N,false);
    finished.assign(N,false);
    pos = -1;
    dfs(G,0,-1);
    set<int> cycle;
    while(!hist.empty()){
        int t = hist.top();
        cycle.insert(t);
        hist.pop();
        if(t==pos) break;
    }
    int Q;cin>>Q;
    REP(i,Q){
        int a,b;
        cin>>a>>b;
        --a,--b;
        if(cycle.count(a) && cycle.count(b)) cout<<2<<endl;
        else cout<<1<<endl;
    }
}

