import Data.List

split' :: String -> [Int]
split' s = map read [(fst . a) s , (tail . snd . a) s]
  where a s = splitAt (head $ elemIndices ',' s) s

conv :: Int -> Int -> [Int] -> [Int]
conv a b list = (take min' list) ++ (list !! max'):[] ++ (drop (min'+1) $ take max' list) ++ (list !! min'):[] ++ (drop (max'+1) list)
  where min' = min a b - 1
        max' = max a b - 1

solve :: [Int] -> [String] -> [Int]
solve ns [] = ns
solve ns (x:xs) = solve (conv (head $ split' x) (last $ split' x) ns) xs

main = getContents >>= mapM_ print . (\(x:_:xs) -> solve [1..read x] xs) . lines