#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

vector<vector<ll>> graph;
vector<bool> leg;


int main()
{
  ll N; cin>>N;
  graph=vector<vector<ll>>(N,vector<ll>(0));
  vector<ll> deg(N,0);
  leg=vector<bool>(N,false);
  rep(i,N){
    ll u,v; cin>>u>>v; u--; v--;
    graph.at(u).push_back(v);
    graph.at(v).push_back(u);
    deg.at(u)++; deg.at(v)++;
  }
  
  //後退解析
  queue<ll> que;
  rep(i,N){
    if(deg.at(i)==1){
      leg.at(i)=true;
      que.push(i);
    }
  }
  while(!que.empty()){
    ll v=que.front(); que.pop();
    for(auto nv:graph.at(v)){
      if(leg.at(nv)) continue;
      deg.at(nv)--;
      if(deg.at(nv)==1){
        leg.at(nv)=true;
        que.push(nv);
      }
    }
  }
  
  ll Q; cin>>Q;
  rep(i,Q){
    ll a,b; cin>>a>>b; a--; b--;
    if(!leg.at(a)&&!leg.at(b)) cout<<2<<endl;
    else cout<<1<<endl;
  }
    
  return 0;
}
