Physics

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

There are nn balls on a smooth horizontal straight track. The track can be considered to be a number line. The balls can be considered to be particles with the same mass.

At the beginning, ball ii is at position X_iX\_i. It has an initial velocity of V_iV\_i and is moving in direction D_i=±1D\_i = \pm 1.

Additionally, a constant CC is given. At any moment, ball ii has acceleration A_iA\_i and velocity V_iV\_i, they have the same direction, and magically satisfy the equation that A_iV_i=CA\_i \cdot V\_i = C.

As there are multiple balls, they may collide with each other during the movement. We suppose all collisions are perfectly elastic collisions.

There are multiple queries. Each query consists of two integers tt and kk. Your task is to find out the kk-th smallest velocity of all the balls exactly tt seconds after the beginning.

Note that perfectly elastic collision is defined as one in which there is no loss of kinetic energy in the collision.

입력

The first line of the input contains two integers nn and CC (1n1051 \le n \le 10^5, 1C1091 \le C \le 10^9).

Then nn lines follow. The ii-th of them contains three integers V_iV\_i, X_iX\_i, D_iD\_i. V_iV\_i denotes the initial velocity of ball ii (1V_i1051 \le V\_i \le 10^5), X_iX\_i denotes the initial position of ball ii (1X_i1091 \le X\_i \le 10^9), D_iD\_i denotes the direction ball ii moves in.

The next line contains an integer 1q1051 \le q \le 10^5, denoting the number of queries. After that, qq lines follow. Each line contains two integers 1t1091 \le t \le 10^9 and 1kn1 \le k \le n.

출력

For each query, print a single line containing the answer with absolute error at most 10310^{-3}.