front=-1
rear=-1
res=[]

for _ in range(int(input())):
    s=input().split()
    
    if s[0]=="Enqueue":
        res.append(s[1])
        rear+=1
    
    if s[0]=="Dequeue":
        if front==rear:
            print("Empty")
        else:
            print(res[0])
            front+=1
            res.pop(0)

front=-1
rear=-1
res=[]

for _ in range(int(input())):
    s=input().split()
    
    if s[0]=="Enqueue":
        res.append(s[1])
        rear+=1
    
    if s[0]=="Dequeue":
        if front==rear:
            print("Empty")
        else:
            print(res[0])
            front+=1
            res.pop(0)
