import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  s <- T.getLine :: IO T.Text
  (q : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  queries <- sequence . replicate q $ T.words <$> T.getLine :: IO [[T.Text]]
  let
    queries' :: [Maybe (Bool, Char)]
    queries' = map f queries
      where
        f (t : fc) | unsafeTextToInt t == 1 = Nothing
                   | otherwise       = Just . ((,) <$> (== 1) . unsafeTextToInt . fst <*> T.head . snd) . unsafeListToTuple $ fc
    b :: Bool
    pf, sf :: String
    (b, pf, sf) = foldl step (True, "", "") $ queries'
      where
        step :: (Bool, String, String) -> Maybe (Bool, Char) -> (Bool, String, String)
        step (b', pf', sf') = g
          where
            g Nothing                   = (not b', sf', pf')
            g (Just (f, c)) | f         = (b', c : pf', sf')
                            | otherwise = (b', pf', c : sf')
    s' :: T.Text
    s' | b         = s
       | otherwise = T.reverse s
  T.putStrLn $ T.pack pf `T.append` s' `T.append` T.pack (reverse sf)

unsafeListToTuple :: [a] -> (a, a)
unsafeListToTuple (x : y : _) = (x, y)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
