import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  rs <- getLine
  unless (rs == "-") $ do
    solve rs <$> getLine <*> getLine >>= putStrLn
    main

solve :: String -> String -> String -> String
solve rs gs ds = case f (tail rs, gs, Just (head rs), []) ds of
                  Just ps -> reverse ps
                  Nothing -> case f (rs, tail gs, Just (head gs), []) ds of
                    Just qs -> reverse qs
                    Nothing -> ""
  where
    f :: (String, String, Maybe Char, String) -> String -> Maybe String
    f ([], [], Nothing, zs) [] = Just zs
    f (_, _, Nothing, _) _ = Nothing
    f (xs, ys, Just c, zs) []
      | null ys = f (xs, [], Nothing, c:zs) []
      | otherwise = f (xs, tail ys, Just (head ys),c:zs) []
    f (xs, ys, Just c, zs) (p:ps)
      | c == p && null xs = f ([], ys, Nothing, zs) ps
      | c == p            = f (tail xs, ys, Just (head xs), zs) ps
      | c /= p && null ys = f (xs, [], Nothing, c:zs) (p:ps)
      | otherwise = f (xs, tail ys, Just (head ys), c:zs) (p:ps)