This page is still under construction.

Parts of this page are still being built. What you see may change.

Queries

Time limit10sMemory limit128 MB

Summary
Maintain a point set under deletions and report the leftmost point within S below the current highest y, breaking ties by higher y.
Level

Medium6 of 10

Topics
Segment tree, Sorting
Solved
No attempts yet

Problem

You are given a set of points Z and a tolerance value S. Write a program that processes two kinds of operations:

  • Remove: delete a given point from the set Z.
  • Find: report the "upper-left point" of the set Z.

The upper-left point is defined as follows. Let ymax⁡y_{\max} be the largest yy-coordinate among the points currently in Z. Consider as candidates every point whose yy-coordinate is smaller than ymax⁡y_{\max} by at most S, that is, every point with y≥ymax⁡−Sy \ge y_{\max} - S. Among the candidates, the upper-left point is the one with the smallest xx-coordinate (the leftmost one). If several candidates share the smallest xx-coordinate, choose the one with the largest yy-coordinate (the highest one).

Input

The first line contains the number of test cases TT (1≤T≤101 \le T \le 10). The test cases follow.

The first line of each test case contains two space-separated integers NN and SS (1≤N≤1051 \le N \le 10^5, 0≤S≤1090 \le S \le 10^9), the initial size of the set Z and the tolerance value. Each of the next NN lines contains two space-separated integers PXP_X and PYP_Y (−109≤PX,PY≤109-10^9 \le P_X, P_Y \le 10^9), describing a point of Z. All points within one test case are distinct.

The next line contains an integer MM (1≤M≤2⋅1051 \le M \le 2 \cdot 10^5), the number of operations to perform. Each of the following MM lines has one of the two forms:

  • USUN PXP_X PYP_Y : remove the point (PX,PY)(P_X, P_Y) from the set Z.
  • ZNAJDZ : find the upper-left point.

A point named in a remove operation is guaranteed to be present in Z at that moment. A find operation is never issued while Z is empty.

Output

For every find (ZNAJDZ) operation, print the coordinates of the found point as x y on its own line.

Examples3

  1. Example 1

    Input
    1
    5 1
    1 1
    1 3
    2 2
    3 2
    3 3
    7
    ZNAJDZ
    USUN 1 3
    ZNAJDZ
    USUN 2 2
    ZNAJDZ
    USUN 3 3
    ZNAJDZ
    
    Expected output
    1 3
    2 2
    3 3
    1 1
    
  2. Example 2

    Input
    1
    4 0
    5 10
    2 10
    0 5
    7 10
    6
    ZNAJDZ
    USUN 2 10
    ZNAJDZ
    USUN 5 10
    USUN 7 10
    ZNAJDZ
    
    Expected output
    2 10
    5 10
    0 5
    
  3. Example 3

    Input
    2
    1 5
    0 0
    1
    ZNAJDZ
    3 3
    -3 2
    -3 7
    4 7
    5
    ZNAJDZ
    USUN -3 7
    ZNAJDZ
    USUN 4 7
    ZNAJDZ
    
    Expected output
    0 0
    -3 7
    4 7
    -3 2