# Akame

Statement:

Akame is training on an infinite 2D Cartesian plane. There is an infinitely long rigid and vertical string at each integer x-coordinate. She takes out her katana, Murasame, and makes $N$ $N$ infinitely long slashes on the plane. Each slash can be seen as a line with the equation $Ax+By=C$ $Ax + By = C$, for some $A$ $A$, $B$ $B$, and $C$ $C$. A slash will never be a vertical line.

Each string Akame slashes will immediately be broken into two smaller strings. For example, a string originally from $\left(5,-\mathrm{\infty }\right)$ $(5, -\infty)$ to $\left(5,\mathrm{\infty }\right)$ $(5, \infty)$ severed by the line $0x+1y=3$ $0x + 1y = 3$ will be broken into the two strings $\left(5,-\mathrm{\infty }\right)$ $(5, -\infty)$ to $\left(5,3\right)$ $(5, 3)$ and $\left(5,3\right)$ $(5, 3)$ to $\left(5,\mathrm{\infty }\right)$ $(5, \infty)$. A string is considered disconnected if it is of a finite length. For example, the string from $\left(1,9\right)$ $(1, 9)$ to $\left(1,\mathrm{\infty }\right)$ $(1, \infty)$ is not of finite length, but the string from $\left(8,-3\right)$ $(8, -3)$ to $\left(8,4\right)$ $(8, 4)$ is.

There are $M$ $M$ points on strings Akame wants to disconnect. A point is said to be disconnected if it is either slashed or the string it's on is disconnected. To measure her performance, Akame would like to know the earliest moment (that is, after which slash) each point is disconnected. The slashes are numbered from $1$ $1$ to $N$ $N$.

Input:

The first line of input will have $N$ $N$ and $M$ $M$, separated by a single space.

The next $N$ $N$ lines of input will each describe one of Akame's slashes, with $A$ $A$, $B$ $B$, and $C$ $C$ separated by spaces.

The next $M$ $M$ lines of input will each describe a point Akame wants to disconnect, with $X\mathrm{_}i$ $X\_i$ and $Y\mathrm{_}i$ $Y\_i$.

Output:

There should be $M$ $M$ lines of output. The $i-th$ $i-th$ line should contain the smallest index of the slash that after it is performed, the $i-th$ $i-th$ point is disconnected. If the $i-th$ $i-th$ point is never disconnected, print -1 instead.

Constraints:

$1\le N\le 500\phantom{\rule{thinmathspace}{0ex}}000$ $1 \le N \le 500\,000$

$1\le M\le 500\phantom{\rule{thinmathspace}{0ex}}000$ $1 \le M \le 500\,000$

$0\le A,|C|\le 30\phantom{\rule{thinmathspace}{0ex}}000$ $0 \le A, |C| \le 30\,000$

$1\le |B|\le 30\phantom{\rule{thinmathspace}{0ex}}000$ $1 \le |B| \le 30\,000$

$0\le |X\mathrm{_}i|,|Y\mathrm{_}i|\le {10}^{9}$ $0 \le |X\_i|, |Y\_i| \le 10^9$

Example input 1
3 5
0 1 3
0 1 5
0 1 7
1 2
1 3
1 4
1 5
1 6

Example output 1
-1
1
2
2
3

Example input 2
10 10
81 -36 72
64 -69 24
23 47 47
83 36 18
1 25 77
12 -81 -3
13 -90 -34
23 19 -34
19 23 78
50 -96 82
56 59
85 47
46 -23
1 13
-74 -69
23 99
-98 72
-31 -65
-78 76
9 -69

Example output 2
2
3
4
-1
2
-1
4
2
4
-1

Time and memory limit:

• 10s
• 1024MB

Problem source: DMOJ