Description
Dom Cobb 和他的搭檔 Arthur 通過進入目標的潛意識來執行非法行為。他們使用夢中夢的兩級夢策略來提取有價值的信息。 入夢者可能被突然的("Kick")驚醒,或者可能在夢中死去。
現在 Dom 需要你的幫助。因為他有一項複雜的任務。他必須經歷很多人的夢境。 他從一個人的夢境旅行到另一個人的夢境。但是他太累了,以至於他無法再知道自己是醒著還是在別人的夢裡。
現在有 n 個詢問去處理,每個詢問會是以下幾種形式之一:
"Sleep X"——這意味著名為 X 的人將要睡覺,而 Dom 將進入 X 的夢境,從前個人的夢境進去(如果有的話)。
"Kick"——這意味著 Dom 進入其夢中的當前人將被喚醒,Dom 將從他進入此夢境的地方返回到前一個人的夢境中。如果 Dom 不再存在於任何人的夢境中,請忽略此查詢。
"Test"——這意味著 Dom 想知道他現在在誰的夢境裡。 您必須輸出此人的姓名。 如果此時 Dom 不在任何人的夢中,你必須輸出"Not in a dream"
Dom Cobb and his partner Arthur perform illegal stuffs by entering the subconscious minds of their targets. They use two-level dream within a dream strategy to extract valuable information. Dreamers are awakened either by a sudden shock (a “kick”), or they may die in the dream.
Now Dom wants your help. Because he has a complex assignment. He has to go through a lot of people’s dreams. He travels from one person’s dream to another person’s dream. He is too consumed that he can no longer keep track whether he is awake or in someone else’s dream.
He will give you n queries to process, each of the queries will be in one of the following forms:
‘Sleep X’ — This means person named X will be sleeping and Dom is going into X’s dream, from the previous person’s dream (if any).
‘Kick’ — This means the current person in whose dream Dom has entered, will be awaken, and Dom will return to the previous person’s dream from where he came to this dream. If Dom is not in anyone’s dream anymore, ignore this query.
‘Test’ — This means Dom wants to know whose dream he is in at the moment. You have to print the person’s name. If Dom is not in anyone’s dream at the moment, you have to print ‘Not in a dream’ (without the quotes).
Input
第一行包含一個整數 n (1 ≤ n ≤ 10000),即查詢次數。以下 n 行中的每一行都將包含上述三個查詢之一。
對於"Sleep X"查詢,X 將是一個僅由大寫或小寫字母組成且長度不超過 15 個字元的字串。
First line will contain an integer n (1 ≤ n ≤ 10000), the number of queries. Each of the following n lines will contain one of the three queries mentioned above. For the case of ‘Sleep X’ query, X will be a string composed of only uppercase or lowercase letters and no more than 15 characters long.
Output
對於每個“Test”查詢,輸出 Dom 所在的夢境的人的名字,與輸入中出現的完全一樣。 如果 Dom 不在任何人的夢境中,則輸出“Not in a dream”。
For each of the ‘Test’ queries, print the name of the person whose dream Dom is in right now exactly as it appeared in the input. If Dom is in no one’s dream, output the line ‘Not in a dream’. Checksample input and output for details.