• [1184] Elaine's Queue

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • Just these days, we've learned about "Queue". It's a kind of data structure.
    Elaine is cranky. She made her own Queue.
    That Queue only has two operations:

    • Top x : Make the element x to the top of the Queue.
    • Next: Output the top element and pop it and then push it to the back of the Queue.


    SORRY, because of the bug of Judge Core. The code "remove" will be judged as "DANGEROUS_CODE". We will fix it next time.
  • 输入
  • The first line is an integer T, indicates the number of cases.
    Then follow T cases.
    The first line of each case has two integer n and m (n, m <= 1000), indicate the number of elements and operations.
    Then follow m lines of operations. Each line is an operation.
  • 输出
  • For each "Next" operation, output the answer.
  • 样例输入
  • 2
    10 5
    Top 4
    Next
    Top 5
    Next
    Next
    8 6
    Next
    Next
    Top 7
    Next
    Top 4
    Next
    
  • 样例输出
  • 4
    5
    1
    1
    2
    7
    4
    
  • 提示
  • 来源
  • Original: ZJUT
    Revise: XadillaX
    
  • 操作

显示春菜