import Control.Applicative
import Control.Monad
import Control.Monad.State

type Dictionary = StateT [String] IO ()

main = do
        n <- readLn
        execStateT (replicateM n runQuery) []

insert :: String -> Dictionary
insert str = do
        dict <- get
        put $ insert' str dict

insert' :: String -> [String] -> [String]
insert' str [] = [str]
insert' str (x:xs)
    | str `compare` x == GT = x : insert' str xs
    | str `compare` x == EQ = (x:xs)
    | str `compare` x == LT = str : x : xs

find :: String -> Dictionary
find str = do
        dict <- get
        case find' str dict of
            False -> liftIO $ putStrLn "no"
            True  -> liftIO $ putStrLn "yes"

find' :: String -> [String] -> Bool
find' str [] = False
find' str (x:xs)
    | str `compare` x == GT = find' str xs
    | str `compare` x == EQ = True
    | str `compare` x == LT = False

runQuery = do
        com <- liftIO getCommand
        com

getCommand :: IO Dictionary
getCommand = do
        [com,str] <- words<$>getLine
        case com of
            "q"      -> return $ return ()
            "insert" -> return $ insert str
            "find"   -> return $ find str
            "print"  -> return $ printDict

printDict :: Dictionary
printDict = get >>= \d -> liftIO $ mapM_ print d