import Control.Monad
import Data.List

initial_state :: Int -> [[Int]]
initial_state 0 = []
initial_state n = ([n-1]) : (initial_state (n-1))

find' :: Int -> [[Int]] -> [Int]
find' x (st:sts)
    | elem x st = st
    | otherwise = find' x sts

drop' :: Int -> [[Int]] -> [[Int]]
drop' _ [[]] = [[]]
drop' _ [] = []
drop' x (st:sts)
    | elem x st = sts
    | otherwise = st : (drop' x sts)

unite :: Int -> Int -> [[Int]] -> [[Int]]
unite x y state =
    let xs  = find' x state
        ys  = find' y state
        tmp = drop' x $ drop' y state
    in
      tmp ++ [ union xs ys ]

same :: Int -> Int -> [[Int]] -> String
same x y state =
    let set = find' x state
    in
      if elem y set
      then "1"
      else "0"

--action :: Int -> Int -> Int -> [[Int]] -> IO [[Int]]
action code x y state =
  case code of
    0 -> do
      return $ unite x y state
    1 -> do
      putStrLn $ same x y state
      return state

main = do
  c1 <- getLine
  let l1 = map read $ words c1 :: [Int]
      n = l1!!0
      state = initial_state n
  c2 <- getContents
  let i0 = map words $ lines c2 
      i = map (map read) i0

  foldM_ (\st (i0:i1:i2:is) -> action i0 i1 i2 st) state i