Chef and Remissness

Practice this coding question on Coding Gurukul.

Problem statement

Two kitchen staff members counted orders during the same service period, but their notes do not reveal which orders both of them counted. One person recorded a orders and the other recorded b. Each person counted distinct orders in their own list. The manager wants the smallest and largest possible number of distinct orders represented by the two lists together. Your task For each test case, determine the minimum possible size and the maximum possible size of the union of two sets having sizes a and b. The lists may overlap completely as far as their sizes allow, or they may have no order in common. Print both bounds. Important details The minimum assumes as much overlap as possible; the maximum assumes none. Do not subtract the smaller count from the larger. Both reported bounds describe total distinct orders, not the number counted twice. Worked example For a = 4 and b = 7, all four orders from the smaller list could appear in the larger, giving 7 total. With no overlap there are 11. Print 7 11.

Input format

First line: T. Next T lines: a b.

Output format

Print the minimum and maximum possible totals, separated by a space.

Constraints

1 <= T <= 1000; 0 <= a,b <= 1000000000.

Sample input

1
4 7

Sample output

7 11

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