tst q d children sals = do
    qstr <- getLine
    let (v : k : _) = map read (words qstr)
    --let d' =  snd $ (f (v + d) children sals) !! (pred k)
    let d' =  snd $ g (v + d) (pred k) children sals
    putStrLn $ show d'
    tst (pred q) d' children sals
tst q d children sals = do
    qstr <- getLine
    let (v : k : _) = map read (words qstr)
    --let d' =  snd $ (f (v + d) children sals) !! (pred k)
    let d' =  snd $ g (v + d) (pred k) children sals
    putStrLn $ show d'
    tst (pred q) d' children sals
tst q d children sals = do
    qstr <- getLine
    let (v : k : _) = map read (words qstr)
    --let d' =  snd $ (f (v + d) children sals) !! (pred k)
    let d' =  snd $ g (v + d) (pred k) children sals
    putStrLn $ show d'
    tst (pred q) d' children sals