import os,sys
from pprint import pprint

# Assumptions:
# • 1 ≤ C ≤ 10000 or C = −1
# • 1 ≤ Nk, Nv ≤ 10000
# • 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”
# • Time constraint will be imposed on VPL and timeout is possible

CACHE_LEN_UNLIMITED=-1
KEY_VALUE_DIFFERENT_ERROR='Warning: number of keys and values are not the same'
NULL = None
MAX_OPER=1

cache = []
IDX_KEY=0
IDX_VALUE=1
IDX_OPER=2

def GETCommand(cache, key):
  global MAX_OPER
  # pos in cache = textual pos - 1
  # can key found ?
  # FROM ASSUMPTIONS: Input keys are unique, no duplicates
  
  key_found = False

  for i in range(0,len(cache)):
    if (cache[i][0] == int(key)):
      MAX_OPER+=1
      cache[i][IDX_OPER] = MAX_OPER
      print(cache[i][IDX_VALUE])
      key_found=True
      break

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

  pass

def PUTCommand(key, value):
  global MAX_OPER
  # FROM ASSUMPTION: Input keys can be converted to integers

  if LRU_CACHE_LEN == CACHE_LEN_UNLIMITED:
    # try find key in cache, if found replace it
    # if not append into cache
    found = False
    for i in range(0,len(cache)):
      if (cache[i][IDX_KEY] == int(key)):
        cache[i][IDX_VALUE] = value
        cache[i][IDX_OPER] = MAX_OPER
        MAX_OPER+=1
        found = True
        break

    if not(found):
      cache.append([int(key), value, MAX_OPER])

  else:
    # check if cache length already reach the max one
    if (len(cache) < LRU_CACHE_LEN):
      # try find key in cache, if found replace it
      # if not append at the end of list
      found = False
      for i in range(0,len(cache)):
        if (cache[i][IDX_KEY] == int(key)):
          cache[i][IDX_VALUE] = value
          cache[i][IDX_OPER] = MAX_OPER
          MAX_OPER+=1
          found = True
          break

      if not(found):
        cache.append([int(key), value, MAX_OPER])
      
    else:
      # try find key in cache, if found replace it
      # if not replace the lowest oper one
      found = False
      min_oper = min(map(lambda x: x[IDX_OPER], cache))
      
      for i in range(0,len(cache)):
        if (cache[i][IDX_KEY] == int(key)):
          cache[i][IDX_VALUE] = value
          cache[i][IDX_OPER] = MAX_OPER
          MAX_OPER+=1
          found = True
          break

      if not(found):
        for i in range(0,len(cache)):
          if (cache[i][IDX_OPER] == min_oper):
            MAX_OPER+=1
            cache[i] = [int(key), value, MAX_OPER]


  MAX_OPER+=1
  return cache

def EndCommand():
  # reformat for print
  cache_temp = list(map(lambda x: [x[IDX_KEY],x[IDX_VALUE]], cache))
  print(cache_temp)
  sys.exit()

# first one = cache_len
LRU_CACHE_LEN = int(input())
KEYS = input()
VALUES = input()

# REQUIREMENTS: Keys must be stored as integers.
list_keys = list(map(lambda x: int(x), KEYS.split(',')))
len_list_keys = len(list_keys)

# REQUIREMENTS: Values must be stored as strings.
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 key, value in zip(list_keys, list_values):
    cache.append([key, value, MAX_OPER])
    MAX_OPER+=1
  # cache = list(map(lambda x: [x[0],x[1]], zip(list_keys, list_values)))

# REQUIREMENTS: If the cache capacity is larger than or equal to the number of data items
elif (LRU_CACHE_LEN >= len_list_keys):
  for key, value in zip(list_keys, list_values):
    if (len(cache) >= LRU_CACHE_LEN):
      cache.pop(0)
    cache.append([key,value, MAX_OPER])
    MAX_OPER+=1
  # cache = list(map(lambda x: [x[0],x[1]], zip(list_keys, list_values)))

# 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 key, value in zip(list_keys, list_values):
    if (len(cache) >= LRU_CACHE_LEN):
      cache.pop(0)
    cache.append([key,value, MAX_OPER])
    MAX_OPER+=1

else:
  pass

while True:
  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()

  else:
    pass
