switch :: Int -> Int -> [a] -> [a]
switch p c l = middle ++ top ++ bottom
  where
    top = take (p - 1) l
    middle = take c $ drop (p - 1) l
    bottom = drop (p + c - 1) l

switches :: [Int] -> [Int] -> [Int]
switches [] l = l
switches (p:c:xs) l = switches xs (switch p c l)

ans :: [Int] -> String
ans [0,0] = ""
ans (n:r:xs) = (show . head $ switches ops [n,n-1..1]) ++ "\n" ++ (ans lsx)
  where
    ops = take (2 * r) xs
    lsx = drop (2 * r) xs

rInt :: String -> Int
rInt str = read str :: Int  -- rInt ?????? read Int ?????\?s

main = do
  input <- getContents
  let i = concat $ map ((map rInt) . words) $ lines input
  putStrLn . ans $ i