# Assumptions:
# - 1 ≤ C ≤ 1000 or C = −1
# - 1 ≤ Nk, Nv ≤ 1000
# - Input keys can be converted to integers
# - Input keys are unique, no duplicates
# - Input values are non-null string
# - None of the values will be equal to “NULL”

CACHE_LEN_UNLIMITED=-1
KEY_VALUE_DIFFERENT_ERROR='Warning: number of keys and values are not the same'
NULL = None
cache = []
IDX_KEY=0
IDX_VALUE=1

def GETCommand(cache, key):
  # ASSUMPTIONS: Input keys are unique, no duplicates
  # For every get operation, 
  # print the value of the key-value pair if the key exists, 
  # otherwise print “NULL”
  
  key_found = False
  for i in range(0,len(cache)):
    if (cache[i][IDX_KEY] == int(key)):
      print(cache[i][IDX_VALUE])
      cache.append(cache.pop(i))
      key_found=True
      break

  if not(key_found):
    print("NULL")

  pass

def PUTCommand(key, value):
  # ASSUMPTION: Input keys can be converted to integers
  if LRU_CACHE_LEN != CACHE_LEN_UNLIMITED:
    if (len(cache) >= LRU_CACHE_LEN):
      cache.pop(0)
  cache.append([int(key), value])

  return cache

def EndCommand():
  print(cache)

def ConvertToInt(input_list):
  output = []
  for i in range(0,len(input_list)):
    output.append(int(input_list[i]))
  return output


# 1st input, Input keys can be converted to integers
LRU_CACHE_LEN = int(input())
# 2nd input, keys
KEYS = input()
# 3rd input, values
VALUES = input()

# REQUIREMENTS: Keys must be stored as integers.
# ASSUMPTIONS: Input keys are unique, no duplicates
# ASSUMPTIONS: Input keys can be converted to integers
list_keys = ConvertToInt(KEYS.split(','))
len_list_keys = len(list_keys)

# REQUIREMENTS: Values must be stored as strings.
# ASSUMPTIONS: Input values are non-null string
list_values = list(VALUES.split(','))
len_list_values = len(list_values)

# setup cache
# REQUIREMENTS: If the numbers of keys and values are different, prints "Warning: number of keys and values are not the same" and outputs an empty cache.
if (len_list_keys != len_list_values):
  print(KEY_VALUE_DIFFERENT_ERROR)

# REQUIREMENTS: If the cache capacity is larger than or equal to the number of data items
elif (LRU_CACHE_LEN == CACHE_LEN_UNLIMITED):
  for i in range(0, len(list_keys)):
    key = list_keys[i]
    value = list_values[i]

    cache.append([key, value])

# REQUIREMENTS: If the cache capacity is larger than or equal to the number of data items
elif (LRU_CACHE_LEN >= len_list_keys):
  for i in range(0, len(list_keys)):
    key = list_keys[i]
    value = list_values[i]

    if (len(cache) >= LRU_CACHE_LEN):
      cache.pop(0)
    cache.append([key,value])

# REQUIREMENTS:
# If the cache capacity is smaller than the number of data items, 
# keeps only those that are near the end of the inputs (right) up to the capacity
elif (LRU_CACHE_LEN < len_list_keys):
  for i in range(0, len(list_keys)):
    key = list_keys[i]
    value = list_values[i]

    if (len(cache) >= LRU_CACHE_LEN):
      cache.pop(0)
    cache.append([key,value])

else:
  pass

loop_exit = False
while not(loop_exit):
  command = input()
  command_splitted = command.split(',') 
  command_with_para = len(command_splitted) > 1

  if (command_splitted[0] == 'get'):
    cache_pos = command_splitted[1]
    GETCommand(cache, cache_pos)

  elif (command_splitted[0] == 'put'):
    [put_key, put_value] = command_splitted[1:3]
    cache = PUTCommand(put_key, put_value)

  elif command == 'end':
    EndCommand()
    loop_exit = True
  else:
    pass