#C14215. Custom Dictionary Sort

    ID: 43840 Type: Default 1000ms 256MiB

Custom Dictionary Sort

Custom Dictionary Sort

You are given a list of dictionaries and two keys. Your task is to sort the list in ascending order, using the value corresponding to the first key as the primary sort criterion and the value corresponding to the second key as the tie‐breaker. More formally, if each dictionary x contains keys key1 and key2, then the sorting condition is defined as follows:

( x_1 < x_2 \iff (x_1[key1], x_1[key2]) < (x_2[key1], x_2[key2]) )

Implement the sorting according to the above rule. In the input, the dictionaries are represented by their two numerical values (one for each key).

inputFormat

Input is given via standard input (stdin). The first line contains two space-separated strings representing the primary key and secondary key. The second line contains an integer (N) representing the number of dictionaries. Each of the next (N) lines contains two integers corresponding to the values of the primary key and the secondary key, respectively.

outputFormat

Output the sorted list of dictionaries to standard output (stdout). Each line should contain the two integers (the values corresponding to the primary and secondary keys) separated by a space. The dictionaries must be sorted in ascending order by the primary key; in the event of a tie, sort by the secondary key. Formally, sort based on the tuple ((x[key1], x[key2])).## sample

a b
3
2 3
1 4
2 1
1 4

2 1 2 3

</p>