import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

const long MOD = 998244353;
const long INF = 1L << 59;

void main() {
    auto N = readln.chomp.to!int;
    auto G = new int[][](N);
    foreach (_; 0..N) {
        auto s = readln.split.map!(to!int);
        G[s[0] - 1] ~= s[1] - 1;
        G[s[1] - 1] ~= s[0] - 1;
    }

    auto loop = new bool[](N);
    auto used = new bool[](N);
    auto prev = new int[](N);
    fill(prev, -1);

    bool dfs(int n, int p) {
        prev[n] = p;
        used[n] = true;
        foreach (m; G[n]) {
            if (used[m] && m != p) {
                for (int x = n; ; x = prev[x]) {
                    loop[x] = true;
                    if (x == m) break;
                }
                return true;
            }
            if (m != p && dfs(m, n)) {
                return true;
            }
        }
        return false;
    }


    dfs(0, -1);
    auto Q = readln.chomp.to!int;
    while (Q--) {
        auto s = readln.split.map!(to!int);
        writeln( (loop[s[0] - 1] && loop[s[1] - 1]) ? 2 : 1 );
    }
}

