n = int(input())
namespaces = {'global' : ''}
variables = {}
def get_namespace(ns, v):
if ns == '' or ns not in namespaces.keys():
return 'None'
if ns not in variables.keys():
return get_namespace(namespaces[ns], v)
if v in variables[ns]:
return ns
return get_namespace(namespaces[ns], v)
for i in range(n):
a, b, c = map(str, input().split())
if a == 'create':
namespaces[b] = c
elif a == 'add':
if b not in variables.keys():
variables[b] = []
variables[b].append(c)
else:
print(get_namespace(b, c))
biA9IGludChpbnB1dCgpKQoKbmFtZXNwYWNlcyA9IHsnZ2xvYmFsJyA6ICcnfQp2YXJpYWJsZXMgPSB7fQoKCmRlZiBnZXRfbmFtZXNwYWNlKG5zLCB2KToKCWlmIG5zID09ICcnIG9yIG5zIG5vdCBpbiBuYW1lc3BhY2VzLmtleXMoKToKCQlyZXR1cm4gJ05vbmUnCglpZiBucyBub3QgaW4gdmFyaWFibGVzLmtleXMoKToKCQlyZXR1cm4gZ2V0X25hbWVzcGFjZShuYW1lc3BhY2VzW25zXSwgdikKCWlmIHYgaW4gdmFyaWFibGVzW25zXToKCQlyZXR1cm4gbnMKCXJldHVybiBnZXRfbmFtZXNwYWNlKG5hbWVzcGFjZXNbbnNdLCB2KQoKCmZvciBpIGluIHJhbmdlKG4pOgoJYSwgYiwgYyA9IG1hcChzdHIsIGlucHV0KCkuc3BsaXQoKSkKCWlmIGEgPT0gJ2NyZWF0ZSc6CgkJbmFtZXNwYWNlc1tiXSA9IGMKCWVsaWYgYSA9PSAnYWRkJzoKCQlpZiBiIG5vdCBpbiB2YXJpYWJsZXMua2V5cygpOgoJCQl2YXJpYWJsZXNbYl0gPSBbXQoJCXZhcmlhYmxlc1tiXS5hcHBlbmQoYykKCWVsc2U6CgkJcHJpbnQoZ2V0X25hbWVzcGFjZShiLCBjKSkK