SORT2D - 2D-SORT

no tags 

Given n points in a two dimensional space, sort all the points in ascending order.

    (x1, y1) > (x2, y2) if and only if (x1 > x2) or (x1 == x2 and y1 < y2) 

Input

The first line consists of an integer t, the number of test cases. Then for each test case the first line consists of an integer n, the number of points. Then the next n lines contains two integers xi, yi which represents the point.

Output

For each test case print the sorted order of the points.

Constraints

1 <= t <= 10

1 <= n <= 100000

-10^9 <= coordinates <= 10^9

NOTE: Strict time limit. Prefer scanf/printf/BufferedReader instead of cin/cout/Scanner.

Example

Input:
1
5
3 4
-1 2
5 -3
3 3
-1 -2

Sample Output:
-1 2
-1 -2
3 4
3 3
5 -3

hide comments
li0n_mmn: 2023-02-14 00:10:57

<snip>
use this comparator for vector of pair
[Simes]: let people experience the joy of figuring it out for themselves.

Last edit: 2023-02-14 08:43:28
yzs: 2020-10-04 08:59:39

[misleading spoiler]! AC in 0.4 sec 1GO

can refer here: [misleading spoiler]

Last edit: 2021-01-27 14:42:07
suryasis: 2017-04-02 10:04:26

Use printf and scanf and also make sure that use std::sort and comp(point p1,point p2)

jigar: 2016-01-19 18:37:32

HI I AM NOT UNDERSTANDING THE QUESTION

Reply : Sort based on x in ascending order. In case of ties, sort based on y in descending order

Last edit: 2016-12-26 18:31:00
sunshine: 2014-10-03 20:19:51

getting tle..help plzz..i have done using structure and selection sort

Last edit: 2014-10-03 20:33:43
cegprakash: 2012-09-02 12:34:27

@Prakash: use scanf and printf instead of cin and cout

Prakash: 2012-08-21 17:48:38

i am getting AC on my system but here it shows WA at 0.73sec. i have used pair<> and sort() from STL..Reply soon..


Added by:cegprakash
Date:2012-04-05
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64