#437. Photoshop Layers
Photoshop Layers
Description
Pixels in a digital picture can be represented with three integers in the range to that indicate the intensity of the red, green, and blue colors. The color of a pixel can be expressed as a six-digit hexadecimal capital string. For example, can be expressed as ''''.
There are layers in Photoshop workstation, labeled by from bottom to top. The screen will display these layers from bottom to top. In this problem, you only need to handle the case that the color of all the pixels in a layer are the same. The color of the -th layer is , the blending mode of the -th layer is ():
- If , the blending mode of this layer is ''Normal''. Assume the previous color displayed on the screen is , now the new color will be .
- If , the blending mode of this layer is ''Linear Dodge''. Assume the previous color displayed on the screen is , now the new color will be , , .
You will be given queries. In the -th query, you will be given two integers and (). Please write a program to compute the final color displayed on the screen if we only keep all the layers indexed within without changing their order. Note that the color of the background is .
Format
Input
The first line contains a single integer (), the number of test cases. For each test case:
The first line of the input contains two integers and (), denoting the number of layers and the number of queries.
In the next lines, the -th line contains an integer and a six-digit hexadecimal capital string , describing the -th layer.
In the next lines, the -th line contains two integers and (), describing the -th query.
Output
For each query, print a single line containing a six-digit hexadecimal capital string, denoting the final displayed color.
Samples
1
5 5
1 64C832
2 000100
2 010001
1 323C21
2 32C8C8
1 2
1 3
2 3
2 4
2 5
64C932
65C933
010101
323C21
64FFE9