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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

vbl seen, finished;
ll pos = -1;
stack<ll> hist;

void dfs(vvll &graph, ll v, ll p){
	seen.at(v) = true;
	hist.push(v);
	vrep(nv, graph.at(v)){
		if(nv == p) continue;
		if(finished.at(nv)) continue;
		if(seen.at(nv) && !finished.at(nv)){
			pos = nv;
			return;
		}
		dfs(graph, nv, v);
		if(pos != -1) return;
	}
	hist.pop();
	finished.at(v) = true;
}

int main(){
  ll n;
	cin >> n;
	vvll graph(n);
	rep(i, 0, n){
		ll u, v;
		cin >> u >> v;
		u--; v--;
		graph.at(u).push_back(v);
		graph.at(v).push_back(u);
	}
	ll q;
	cin >> q;
	vll a, b;
	rep(i, 0, q){
		ll aa, bb;
		cin >> aa >> bb;
		aa--; bb--;
		a.push_back(aa); b.push_back(bb);
	}

	seen.assign(n, false); finished.assign(n, false);
	dfs(graph, 0, -1);
	set<ll> cycle;
	while(hist.size()){
		cycle.insert(hist.top());
		if(hist.top() == pos) break;
		hist.pop();
	}

	rep(i, 0, q) {
		if(cycle.count(a.at(i)) && cycle.count(b.at(i))) cout << 2 << endl;
		else cout << 1 << endl;
	}
}
