#K73242. Mail Sorting System

    ID: 33932 Type: Default 1000ms 256MiB

Mail Sorting System

Mail Sorting System

The Mail Sorting System problem requires you to determine the region in which a given postal address falls. You are provided with several postal code ranges (regions) and a list of addresses (postal codes). For each address, if it lies within a region \( [a_i, b_i] \) (i.e. \( a_i \leq p \leq b_i \)), output the 1-based index of the first matching region; otherwise, output NONE.

Note that the input begins with an integer T indicating the number of test cases. Each test case then provides the list of regions followed by the list of addresses to be checked.

inputFormat

The input is read from standard input (stdin) and follows the format below:

T
m
a1 b1
... 
a_m b_m
k
p1
... 
p_k

Here, T is the number of test cases. For each test case:

  • m is the number of regions, followed by m lines each containing two integers a and b representing the start and end postal codes of the region.
  • k is the number of addresses, followed by k lines each containing an integer postal code.

outputFormat

For each address in each test case, output the 1-based index of the first region that contains the address. If no region contains the address, output NONE. Each result should be printed on a new line to standard output (stdout).

## sample
1
3
100 200
250 300
310 400
4
150
275
310
401
1

2 3 NONE

</p>