#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

int V;
vector<int> G[NUM];
int in_num[NUM];
bool in_cycle[NUM];


int main(){

	scanf("%d",&V);

	for(int i = 0; i < V; i++){
		in_num[i] = 0;
		in_cycle[i] = true;
	}

	int from,to;

	for(int loop = 0; loop < V; loop++){

		scanf("%d %d",&from,&to);
		from--;
		to--;
		in_num[from]++;
		in_num[to]++;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	//次数が1のものから、枝を切っていく
	queue<int> Q;

	for(int i = 0; i < V; i++){
		if(in_num[i] == 1){
			in_cycle[i] = false;
			Q.push(i);
		}
	}

	int adj_node;

	while(!Q.empty()){

		for(int i = 0; i < G[Q.front()].size(); i++){

			adj_node = G[Q.front()][i];
			if(!in_cycle[adj_node])continue;

			in_num[adj_node]--;
			if(in_num[adj_node] == 1){
				in_cycle[adj_node] = false;
				Q.push(adj_node);
			}
		}

		Q.pop();
	}

	int num_query;
	scanf("%d",&num_query);

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		if(in_cycle[from] == true && in_cycle[to] == true){

			printf("2\n");

		}else{

			printf("1\n");
		}
	}

	return 0;
}

