# coding: utf-8 def main(): N = int(input()) seats = [[] for _ in range(20)] for _ in range(N): seats, output = _next(seats) if output: print(output) def _next(seats): funcs = { '0': sit, '1': serve, '2': leave } inputs = input().split(' ') return funcs[inputs[0]](seats, *inputs[1:]) def serve(seats, sushi): for i, s in enumerate(seats): if _index(s, sushi) != -1: seats[i] = remove(s, _index(s, sushi)) return seats, i+1 return seats, -1 def remove(l, i): return list(map(lambda t: t[1], filter(lambda t: t[0] != i, enumerate(l)))) def _index(l, e): if e in l: return l.index(e) else: return -1 def sit(seats, i, *info): i = int(i) seats[i-1] = list(info[1:]) return seats, None def leave(seats, i): i = int(i) seats[i-1] = [] return seats, None if __name__ == '__main__': main()