package main

import (
	"bufio"
	"container/list"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

var (
	scan = NewScanner()
)

func DFS(graph [][]int, forth, back []bool, history *list.List, root, parent int) int {
	forth[root] = true
	history.PushBack(root)
	for _, node := range graph[root] {
		if node == parent || back[node] {
			continue
		}
		if forth[node] && !back[node] {
			return node
		}
		if pos := DFS(graph, forth, back, history, node, root); pos != -1 {
			return pos
		}
	}
	history.Remove(history.Back())
	back[root] = true
	return -1
}

func Solve(graph [][]int, queries [][2]int) []int {
	forth := make([]bool, len(graph), len(graph))
	back := make([]bool, len(graph), len(graph))
	history := list.New()

	pos := DFS(graph, forth, back, history, 0, -1)

	cycleNodes := map[int]bool{}
	for history.Len() > 0 {
		node := history.Remove(history.Back()).(int)
		cycleNodes[node] = true
		if node == pos {
			break
		}
	}

	ans := make([]int, len(queries), len(queries))
	for i, query := range queries {
		if cycleNodes[query[0]] && cycleNodes[query[1]] {
			ans[i] = 2
		} else {
			ans[i] = 1
		}
	}
	return ans
}

func main() {
	N := scan.Int()
	graph := make([][]int, N, N)
	for i := 0; i < N; i++ {
		u, v := scan.Int()-1, scan.Int()-1
		graph[u] = append(graph[u], v)
		graph[v] = append(graph[v], u)
	}
	Q := scan.Int()
	queries := make([][2]int, Q, Q)
	for i := range queries {
		a, b := scan.Int()-1, scan.Int()-1
		queries[i][0], queries[i][1] = a, b
	}
	ans := Solve(graph, queries)
	for _, a := range ans {
		fmt.Println(a)
	}
}

// --------------------------------------------------------------------------------
// Input

type Scanner struct{ *bufio.Scanner }

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 100000000)
	return &Scanner{sc}
}

func (s *Scanner) String() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) StringSlice(l int) []string {
	if l == 0 {
		return []string{}
	}
	sl := make([]string, l, l)
	for i := range sl {
		sl[i] = s.String()
	}
	return sl
}

func (s *Scanner) Int() int {
	n, _ := strconv.Atoi(s.String())
	return n
}

func (s *Scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *Scanner) IntPair() [2]int {
	return [2]int{s.Int(), s.Int()}
}

func (s *Scanner) IntPairSlice(l int) [][2]int {
	if l == 0 {
		return [][2]int{}
	}
	sl := make([][2]int, l, l)
	for i := range sl {
		sl[i] = s.IntPair()
	}
	return sl
}

func (s *Scanner) IntSliceDim2(l1, l2 int) [][]int {
	if l1 == 0 {
		return [][]int{}
	}
	sl := make([][]int, l1, l1)
	for i := range sl {
		sl[i] = s.IntSlice(l2)
	}
	return sl
}

func (s *Scanner) Int64() int64 {
	n, _ := strconv.ParseInt(s.String(), 10, 64)
	return n
}

func (s *Scanner) BigInt() *big.Int {
	return big.NewInt(s.Int64())
}

func (s *Scanner) BigIntSlice(l int) []*big.Int {
	if l == 0 {
		return []*big.Int{}
	}
	sl := make([]*big.Int, l, l)
	for i := range sl {
		sl[i] = s.BigInt()
	}
	return sl
}

func (s *Scanner) Float64() float64 {
	f, _ := strconv.ParseFloat(s.String(), 64)
	return f
}

func (s *Scanner) Float64Slice(l int) []float64 {
	if l == 0 {
		return []float64{}
	}
	sl := make([]float64, l, l)
	for i := range sl {
		sl[i] = s.Float64()
	}
	return sl
}

// --------------------------------------------------------------------------------
// Output

const (
	Yes = "Yes"
	No  = "No"

	YES = "YES"
	NO  = "NO"
)

func PrintBool(v bool, trueStr, falseStr string) {
	if v {
		fmt.Println(trueStr)
	} else {
		fmt.Println(falseStr)
	}
}

// --------------------------------------------------------------------------------
// sort.BigIntSlice

type BigIntSlice []*big.Int

func (sl BigIntSlice) Len() int {
	return len(sl)
}

func (sl BigIntSlice) Less(i, j int) bool {
	return sl[i].Cmp(sl[j]) == -1
}

func (sl BigIntSlice) Swap(i, j int) {
	sl[i], sl[j] = sl[j], sl[i]
}

// --------------------------------------------------------------------------------
// Mint

const (
	Mod = 1000000007
)

type Mint int

func NewMint(value int) Mint {
	return Mint((value%Mod + Mod) % Mod)
}

func (x Mint) Add(y Mint) Mint {
	if v := x + y; v >= Mod {
		return v - Mod
	} else {
		return v
	}
}

func (x Mint) Sub(y Mint) Mint {
	if v := x + Mod - y; v >= Mod {
		return v - Mod
	} else {
		return v
	}
}

func (x Mint) Mul(y Mint) Mint {
	return (x * y) % Mod
}

func (x Mint) pow(n int) Mint {
	if n == 0 {
		return Mint(1)
	}
	a := x.pow(n >> 1)
	a = a.Mul(a)
	if n&1 != 0 {
		a = a.Mul(x)
	}
	return a
}

func (x Mint) Inverse() Mint {
	return x.pow(Mod - 2)
}

func (x Mint) Div(y Mint) Mint {
	return x * y.Inverse()
}

func (x Mint) Neg() Mint {
	return NewMint(int(-x))
}

// --------------------------------------------------------------------------------
// Factorial

type Factorial struct {
	fact        []Mint
	factInverse []Mint
}

func NewFactorial(n int) *Factorial {
	f := new(Factorial)
	f.init(n)
	return f
}

func (f *Factorial) init(n int) {
	fact := make([]Mint, n+1, n+1)
	fact[0] = NewMint(1)
	for i := 1; i <= n; i++ {
		fact[i] = fact[i-1].Mul(NewMint(i))
	}

	inv := make([]Mint, n+1, n+1)
	inv[n] = fact[n].Inverse()
	for i := n; i >= 1; i-- {
		inv[i-1] = inv[i].Mul(NewMint(i))
	}

	f.fact = fact
	f.factInverse = inv
}

func (f *Factorial) Get(n int) Mint {
	return f.fact[n]
}

func (f *Factorial) GetInverse(n int) Mint {
	return f.factInverse[n]
}

func (f *Factorial) Permutation(n, k int) Mint {
	if k < 0 || n < k {
		return 0
	}
	return f.fact[n].Mul(f.factInverse[n-k])
}

func (f *Factorial) Combination(n, k int) Mint {
	if k < 0 || n < k {
		return 0
	}
	return f.fact[n].Mul(f.factInverse[k]).Mul(f.factInverse[n-k])
}

// --------------------------------------------------------------------------------
// PrimeFactorization

func PrimeFactorization(n int) map[int]int {
	m := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			n /= i
			m[i]++
		}
	}
	if n != 1 {
		m[n]++
	}
	return m
}

// --------------------------------------------------------------------------------
// Sieve

type Sieve struct {
	n          int
	primes     []int
	maxFactors []int
}

func NewSieve(n int) *Sieve {
	sieve := &Sieve{
		n:          n,
		primes:     []int{},
		maxFactors: make([]int, n+1, n+1),
	}
	sieve.init()
	return sieve
}

func (s *Sieve) init() {
	s.maxFactors[0] = -1
	s.maxFactors[1] = -1
	for i := 2; i <= s.n; i++ {
		if s.maxFactors[i] != 0 {
			continue
		}
		s.primes = append(s.primes, i)
		s.maxFactors[i] = i
		for j := i * i; j <= s.n; j += i {
			if s.maxFactors[j] == 0 {
				s.maxFactors[j] = i
			}
		}
	}
}

func (s *Sieve) IsPrime(x int) bool {
	return s.maxFactors[x] == x
}

func (s *Sieve) PrimeFactorization(x int) map[int]int {
	m := map[int]int{}
	for x != 1 {
		m[s.maxFactors[x]]++
		x /= s.maxFactors[x]
	}
	return m
}

// --------------------------------------------------------------------------------
// MathUtil

func Pow(x, p int) int {
	pow := 1
	for i := 0; i < p; i++ {
		pow *= x
	}
	return pow
}



Measured memory_bytes: 60392