Under construction

Still being built. Things may change

Driving Test Track

Time limit2sMemory limit1024 MB

Summary
Given n front-radar cars and m corner-radar cars, find the minimum carrier capacity k and the fewest road crossings to move all cars west without mixed types on one side.
Level

Medium7 of 10

Topics
Math, Greedy, Simulation
Solved
No attempts yet

Problem

Hyundai Mobis has run a software academy at its Technical Research Institute in Yongin, Gyeonggi-do, since 2018, where more than 400 researchers can take software job training at the same time. The institute currently has about 800 software designers in Korea, and it plans to grow that number to about 4,000 by 2025, more than five times the current size.

Alongside building software staff at domestic research institutes, the company is expanding its India research institute into a global base for software specialization.

In 2018, it also became the first domestic auto parts maker to form a big data team, and it actively applies big data and artificial intelligence to research and development.

A new driving test track built by Hyundai Mobis is validating two kinds of artificial intelligence software by installing them on real cars. Each software program is linked to a front radar or a corner radar. The test track has n+mn+m cars in total. Of these, nn cars have a front radar, and the other mm cars have a corner radar.

The test track is divided into an east section and a west section. At the start, all cars are driving only in the east section, and you are monitoring the cars from the east section. You can monitor only the section where you are. You cannot monitor the other section.

The two radar types cannot yet communicate with each other. If cars with different radar types are in the section you are not monitoring at the same time, the cars will stop their driving tests. Your goal is to move all cars to the west section without any car stopping its test.

Specifically, a road connects the east and west sections. You can take at least 0 and at most kk cars at once and move from one section to the other.

For example, suppose the east section starts with 3 front radar cars and 2 corner radar cars, and k=2k=2. You can cross the road to the west section with 2 corner radar cars. After you move, you can monitor the west section. Likewise, you can take 2 or fewer cars back from the west section to the east section, and then monitor the east section.

Find the minimum value of kk that moves all cars to the west section without stopping any driving test, and the minimum number of times you must cross the road at that kk. Output both values.

Input

The first line contains the number of test cases TT.

Each of the following lines contains two integers nn and mm, separated by a space, for one test case.

Output

For each test case, print on one line the minimum value of kk and the minimum number of road crossings at that kk, separated by a space. It can be proven that both values are less than 2632^{63} within the input range.

Constraints

  • 1≤T≤100 0001 \leq T \leq 100\,000
  • 1≤n,m≤1091 \leq n, m \leq 10^9

Examples1

  1. Example 1

    Input
    3
    3 3
    2 3
    1 3
    
    Expected output
    3 3
    2 7
    2 5