# your code goes here no_of_lines = int(input()) stack = [] flag = 0 list1 = [] # print('\n') for i in range(0, no_of_lines): list1.append(str(input())) for i in range(0, no_of_lines): # print(str(i)) alter = [] a = list1.pop(0) if flag == 0: if a[0] == 't': if stack: alter = [int(a[8:])] stack = alter + stack else: stack.append(int(a[8:])) elif a[0] == 'p': stack.append(int(a[10:])) elif a[0] == 'b': if stack: print(stack.pop()) else: print('No job for Ada?') elif a[0] == 'f': if stack: print(stack.pop(0)) else: print('No job for Ada?') elif a[0] == 'r': if len(stack) > 1: flag = 1 else: flag = 0 else: if a[0] == 't': stack.append(int(a[8:])) elif a[0] == 'p': if stack: alter = [int(a[10:])] stack = alter + stack else: stack.append(int(a[8:])) elif a[0] == 'b': if stack: print(stack.pop(0)) if len(stack) < 2: flag = 0 else: print('No job for Ada?') elif a[0] == 'f': if stack: print(stack.pop()) if len(stack) < 2: flag = 0 else: print('No job for Ada?') elif a[0] == 'r': flag = 0