1 #include<iostream>
 2 using namespace std;
 3 int stack[100000001];
 4 int top=1;
 5 int main()
 6 {
 7     int n;
 8     cin>>n;
 9     for(int i=1;i<=n;i++)
10     {
11         int a;
12         cin>>a;
13         if(a==2)
14         {
15             if(top==1)
16             {
17                 cout<<"impossible!";
18                 return 0;
19             }
20             else
21             {
22                 top--;
23             }
24         }
25         else if(a==1)
26         {
27             int b;
28             cin>>b;
29             stack[top]=b;
30             top++;
31         }
32         else if(a==3)
33         {
34             cout<<stack[top-1]<<endl;
35         }
36     }
37 /*    if(top==1)
38     {
39         cout<<"impossible!";
40     }
41     else
42     {
43         cout<<stack[top-1];
44     }*/
45     return 0;
46 }