#D1837. Stack

    ID: 1533 Type: Default 1000ms 268MiB

Stack

Stack

Stack is a container of elements that are inserted and deleted according to LIFO (Last In First Out).

For nn stack SiS_i (i=0,1,...,n1i = 0, 1, ..., n-1), perform a sequence of the following operations.

  • push(tt, xx): Insert an integer xx to StS_t.
  • top(tt): Report the value which should be deleted next from StS_t. If StS_t is empty, do nothing.
  • pop(tt): Delete an element from StS_t. If StS_t is empty, do nothing.

In the initial state, all stacks are empty.

Constraints

  • 1n1,0001 \leq n \leq 1,000
  • 1q200,0001 \leq q \leq 200,000
  • 1,000,000,000x1,000,000,000-1,000,000,000 \leq x \leq 1,000,000,000

Input

The input is given in the following format.

n  qn \; q query1query_1 query2query_2 : queryqquery_q

Each query queryiquery_i is given by

0 tt xx

or

1 tt

or

2 tt

where the first digits 0, 1 and 2 represent push, top and pop operations respectively.

Output

For each top operation, print an integer in a line.

Example

Input

3 9 0 0 1 0 0 2 0 0 3 0 2 4 0 2 5 1 0 1 2 2 0 1 0

Output

3 5 2

inputFormat

Input

The input is given in the following format.

n  qn \; q query1query_1 query2query_2 : queryqquery_q

Each query queryiquery_i is given by

0 tt xx

or

1 tt

or

2 tt

where the first digits 0, 1 and 2 represent push, top and pop operations respectively.

outputFormat

Output

For each top operation, print an integer in a line.

Example

Input

3 9 0 0 1 0 0 2 0 0 3 0 2 4 0 2 5 1 0 1 2 2 0 1 0

Output

3 5 2

样例

3 9
0 0 1
0 0 2
0 0 3
0 2 4
0 2 5
1 0
1 2
2 0
1 0
3

5 2

</p>