Second Largest

Practice this coding question on Coding Gurukul.

Problem statement

A robotics club compares three sensor readings during each calibration round. One unusually high or low reading should not determine the reported value, so the calibration log records the middle reading. You are implementing the small selection step used repeatedly by the logging system. Your task For each round, arrange its three integer readings in nondecreasing order and output the second one. This is the second largest value among the three readings. Important details The readings can arrive in any order. Treat each reading as an entry rather than removing repeated values: if two readings are equal, both occupy positions in the sorted order. Do not print the largest reading or the average. Worked example For readings 12, 4 and 9, the sorted order is 4, 9, 12. The middle reading is 9. For 7, 7 and 3, the middle reading is 7.

Input format

The first line contains T. Each of the next T lines contains three integers A B C.

Output format

Print the second largest reading for each round on its own line.

Constraints

1 <= T <= 1000; 1 <= A, B, C <= 1000000000.

Sample input

2
12 4 9
7 7 3

Sample output

9
7

Sign in to run or submit a solution in C++, Java or Python.