
object Main extends App {

  import scala.io.StdIn._


  val n = readLine.trim.toInt
  val nodes = Array.tabulate(n){_ ⇒ new Node()}
  val isVisit = Array.tabulate(n){_ ⇒ false}
  for (_ ← 0 until n){
    val Array(v, u) = readLine.trim.split(' ').map(_.toInt)
    nodes(v - 1).addNode(u - 1)
    nodes(u - 1).addNode(v - 1)
  }
  markLoop(0, nodes, isVisit)
  for (_ ← 0 until readLine.trim.toInt){
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
    println(
      if (nodes(a - 1).isOnLoop && nodes(b - 1).isOnLoop) 2 else 1
    )
  }
  def markLoop(root: Int, nodes: Array[Node], isVisited: Array[Boolean]): Unit = {
    isVisited(root) = true
    nodes(root).edges.flatMap(p ⇒ markLoop(p, root, nodes, isVisited)).headOption match {
      case Some(_) ⇒ nodes(root).isOnLoop = true
      case _ ⇒
    }
  }
  def markLoop(current: Int, parent: Int, nodes: Array[Node], isVisited: Array[Boolean]): Option[Int] = {
    isVisited(current) = true
    nodes(current).edges.find(p ⇒ p != parent && isVisited(p)) match {
      case None ⇒
        nodes(current).edges.filterNot(p ⇒ isVisited(p)).flatMap(p ⇒ markLoop(p, current, nodes, isVisited)).headOption match {
          case None ⇒ None
          case Some(p) if p == current ⇒
            nodes(current).isOnLoop = true
            None
          case Some(p) ⇒
            nodes(current).isOnLoop = true
            Some(p)
        }
      case Some(l) ⇒
        nodes(current).isOnLoop = true
        Some(l)
    }
  }
  class Node{
    private var mEdges: List[Int] = Nil
    def addNode(to: Int): Unit = mEdges ::= to
    def edges: List[Int] = mEdges
    var isOnLoop: Boolean = false
  }
  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
