• + 2 comments

    use this as pattern for IO:

    main :: IO ()
    main = do
        n_temp <- getLine
        let n = read n_temp :: Int
        forM_ [1..n] $ \boh  -> do
            q_temp <- getLine
            let q = read q_temp :: Int
            rawInput <- getMultipleLines q
            let input = [(read (words str !! 0) :: Int, read (words str !! 1) :: Int ) | str <- rawInput]
            -- here starts your code
    
    
    getMultipleLines :: Int -> IO [String]
    getMultipleLines n
        | n <= 0 = return []
        | otherwise = do          
            x <- getLine         
            xs <- getMultipleLines (n-1)    
            let ret = (x:xs)    
            return ret
    

    It works with most input format of HackerRank:

    • First read and parse an integer (n_temp and n)
    • For n times read another number from input called q and read the next q lines with getMultipleLines. It returns a list of q lines as strings.
    • To parse the numbers inside a single line, use list comprehension to iterate on the lines and the function "words" to split the values. This code works if every line contains exactly two integers and put them in a list of type [(Int, Int)]