Ancient Keyboard
Time limit1sMemory limit128 MB
Simulate a keyboard where each of up to 26 keys toggles an LED at two given times, and output the letter matching the LED count at each time step until all intervals end.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
Scientists have found an ancient device that works in a strange way. The device has a keyboard and an output tape. The keyboard has 26 keys, labeled A through Z. Each key has an LED on it (like the Caps Lock key on some keyboards). Every time you press a key, its LED toggles (switching from off to on, or from on to off). Initially all LEDs are off.
To study the output written on the tape, we look at the device in discrete time steps. Consider time . If no LED is on, nothing is written on the tape. If LEDs are on, the -th letter of the English alphabet is written on the tape. For example, if three LEDs are on during a time step, the letter C is written on the tape. This repeats at every time step.
Write a program that simulates this ancient device.
Input
The input contains multiple test cases. The first line contains , the number of test cases that follow. Each of the next blocks describes one test case.
The first line of each block contains one integer . After that, there are lines, each containing one capital letter followed by two integers and . The capital letter is the key that is pressed. The key is pressed for the first time at time step and for the second time at time step . During the interval , that key's LED is on. Within each test case these letters are guaranteed to be distinct.
Output
For each test case, output one line containing the output string written on the tape. (If nothing is written, output an empty line.)