import collections

d=collections.deque()

for _ in range(int(eval(input()))):

 e=eval(input())

 if'i'==e[0]:d.appendleft(e.split()[1])

 else:

  if' '==e[6]:

   m=e.split()[1]

   if m in d:d.remove(m)

  elif len(e)%2:d.popleft()

  else:d.pop()

print((*d))

import collections,sys

d=collections.deque()

eval(input())

for e in sys.stdin.readlines():

 if'i'==e[0]:d.appendleft(e.split()[1])

 else:

  if' '==e[6]:

   m=e.split()[1]

   if m in d:d.remove(m)

  elif len(e)%2:d.pop()

  else:d.popleft()

print((*d))

import collections

d = collections.deque()
for _ in range(int(eval(input()))):
    e = eval(input())
    if "i" == e[0]:
        d.appendleft(e.split()[1])
    else:
        if " " == e[6]:
            m = e.split()[1]
            if m in d:
                d.remove(m)
        elif len(e) % 2:
            d.popleft()
        else:
            d.pop()
print((*d))

import collections, sys

d = collections.deque()
eval(input())
for e in sys.stdin.readlines():
    if "i" == e[0]:
        d.appendleft(e.split()[1])
    else:
        if " " == e[6]:
            m = e.split()[1]
            if m in d:
                d.remove(m)
        elif len(e) % 2:
            d.pop()
        else:
            d.popleft()
print((*d))

-import collections +import collections, sys -for _ in range(int(eval(input()))): -    e = eval(input()) +eval(input()) +for e in sys.stdin.readlines(): +            d.pop() +        else: -        else: -            d.pop()