Note: This problem wasn't part of "Latin American Regional Contest 2016" due to similarity with other problem. During the real contest teams removed the corresponding paper sheet from the problemset. Solves this task at the end if you want to simulate the real contest.
Scientists at the Interstellar Consortium of Planets and Constellations (ICPC) are studying the composition of many celestial objects by analyzing their emission spectrum. The emission spectrum of a celestial object is the spectrum of frequencies of electromagnetic radiation emitted due to its atomic energy transitions, along with the intensity of the emitted radiation. In other words, it corresponds to the intensity of each color for the light radiated by the object.
According to the postulates of quantum mechanics, the emission spectrum of a celestial object is always discrete. Therefore, the ICPC can store the emission spectrum of an object as a sequence of integers where each position in the sequence corresponds to the intensity of a specific wavelength. In this representation of the spectrum, larger numbers correspond to higher emitted intensities, and contiguous positions in the sequence correspond to contiguous wavelengths in the spectrum.
The emission spectrum of a celestial object is the result of very complex physical processes, and may thus vary through its lifetime. Notably, due to complex atomic reactions not yet fully understood, the intensity of two contiguous wavelengths can be swapped at a given time.
The ICPC is studying very closely the emission spectrum of some celestial object at particular wavelengths. However, scientists are having trouble obtaining useful data from their observations. Particularly, given a range of wavelengths and an integer $K$, they are interested in knowing the intensity of the wavelength which has the $K$-th smallest intensity in that range. Given a list of observational events mixing information requested by the scientists and wavelength intensity swaps in the spectrum, your task is to help the scientists by answering their queries.