Under construction

Still being built. Things may change

Ancient Keyboard

Time limit1sMemory limit128 MB

Summary
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 tt. If no LED is on, nothing is written on the tape. If ii LEDs are on, the ii-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 tt, the number of test cases that follow. Each of the next tt blocks describes one test case.

The first line of each block contains one integer nn (0≤n≤26)(0 \le n \le 26). After that, there are nn lines, each containing one capital letter followed by two integers aa and bb (0≤a<b≤1000)(0 \le a < b \le 1000). The capital letter is the key that is pressed. The key is pressed for the first time at time step aa and for the second time at time step bb. During the interval a,a+1,…,b−1a, a+1, \dots, b-1, 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.)

Examples1

  1. Example 1

    Input
    2
    2
    X 2 6
    Y 4 9
    3
    A 1 5
    B 4 8
    C 9 10
    
    Expected output
    AABBAAA
    AAABAAAA