merry = [4,1,4,1,2,1,2,1]
main = do
  s <- getContents
  mapM_ func $ map words $ lines s
  return ()

func s = do
  let s2 = (map read s)
  let ans = snd $ choice $all_list s2 merry []
  putStrLn $ concat $ map show ans

rotate (x:xs) = xs ++ (x:[])

score s m = sum $ zipWith f s m
  where f x y = max 0 (y - x)

all_list s m l = 
  let t = ((score s m),m) in
  if (elem t l)
    then l
    else all_list s (rotate m) (t:l)

choice l = 
  foldl f (100,[5,5,5,5,5,5,5,5]) l
f acc t
  | fst acc == fst t && snd acc > snd t = t
  | fst acc > fst t                     = t
  | otherwise                           = acc