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

vector<vector<int>> v(100010);
bool used[100010];
bool roop[100010];

int ep = -1;

bool dfs(int p,int pre){
    used[p] = 1;
    bool ret = false;
    for(auto i:v[p]){
        if(i!=pre){
            if(used[i]){
                roop[p] = 1;
                roop[i] = 1;
                ep = i;
                return true;
            }
            else{
                ret |= dfs(i,p);
                if(ret){
                    roop[p]=1;
                    break;
                }
            }
        }
    }
    if(p==ep) ret = false;
    return ret;
}



signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);

    }
    dfs(0,-1);
    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(roop[a] && roop[b]){
            cout << 2 << "\n";
        }
        else cout << 1 << "\n";
    }
}
