• + 0 comments
    n_opperations = int(input().strip())
    operations = list()
    
    for _ in range(n_opperations):
        operations.append(input().strip())
    
    string = str()
    done = list()
    
    for ops in operations:
        if ops[0] == '1':
            done.append(ops)
            string += ops[2:]
        elif ops[0] == '2':
            k = int(ops[2:])
            done.append((ops[0], ' ', string[-k:]))
            string = string[:-k]
        elif ops[0] == '3':
            print(string[int(ops[2:])-1])
        elif ops[0] == '4':
            if done[-1][0] == '1':
                string = string[:-len(done[-1][2:])]
                done.pop()
            else:
                string += done[-1][2]
                done.pop()