Under construction

Still being built. Things may change

Number Tower and Queries

Interview

Time limit2sMemory limit1024 MB

Summary
Given a, d, and x, find the floor holding block number x and its position from the left on that floor, where floor i has a + (i-1)d blocks.
Level

Medium4 of 10

Topics
Binary search, Math
Solved
No attempts yet

Problem

Uichan enjoys stacking towers of blocks with numbers on them. One day Seonu found that the towers Uichan builds follow a rule. The rule Seonu found is as follows.

  • The tower Uichan builds has its top at floor 11, and floor 11 has aa blocks.
  • The leftmost block on floor 11 is marked 11, and the numbers increase by 11 moving to the right.
  • The leftmost block on floor i+1i+1 is 11 greater than the rightmost block on floor ii.
  • Floor i+1i+1 has dd more blocks than floor ii.

The figure below shows the tower Uichan built from floor 11 to floor 44 with a=1a=1 and d=2d=2.

Uichan has memorized the position of every numbered block, and he answers QQ queries from Seonu. Each query has one form.

  • a d x: Given aa and dd, which floor holds the block numbered xx, and which position from the left on that floor is it?

Take the figure above as an example. If a=1a=1, d=2d=2, and x=12x=12, Uichan answers (4,3)(4,3). This means the block numbered 1212 is the 3rd number on floor 4.

Input

The first line contains the number of queries QQ that Seonu asks Uichan. (1≤Q≤500 000)(1\leq Q \leq 500\,000)

The next QQ lines each contain aa, dd, and xx, separated by spaces. (1≤a,d,x≤106)(1\leq a,d,x \leq 10^{6})

All values in the input are integers.

Output

For each of the QQ lines, print the floor where the block numbered xx is located, and its position counted from the leftmost block on that floor.

Examples1

  1. Example 1

    Input
    2
    1 2 12
    1 2 17
    
    Expected output
    4 3
    5 1