#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "vector"

using namespace std;

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

	int N,L,R;
	cin >> N;
	vector<vector<int>>edge(N);
	for (int i = 0; i < N; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>dir(N);
	queue<int>Q;
	vector<bool>flag(N, true);
	for (int i = 0; i < N; i++) {
		dir[i] = edge[i].size();
		if (dir[i] == 1) {
			Q.push(i);
			flag[i] = false;
		}
	}
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			dir[i]--;
			if (dir[i] == 1) {
				Q.push(i);
				flag[i] = false;
			}
		}
	}
	int K;
	cin >> K;
	for (int i = 0; i < K; i++) {
		cin >> L >> R;
		L--;
		R--;
		if (flag[R] && flag[L]) {
			cout << 2 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	return 0;
}
