Happy Phone Call

Time limit2sMemory limit128 MB

Problem

In the Kingdom of Changyoung there is a peculiar law about phone calls.

If you get angry at the other person during a call, you go to jail.

To catch people who get angry, the police want to wiretap every phone call.

The police pick employees appropriately to wiretap all calls during certain time windows. Each employee must rest for a very long time before wiretapping.

Write a program that determines how many employees the police must hire in total. If your program is not written correctly, you go to jail together with the person who got angry.

Input

The input consists of several test cases.

The first line of each test case contains the number of phone calls $N$ ($1 \le N < 10{,}000$) and the number of intervals $M$ ($1 \le M < 100$).

Each of the next $N$ lines describes one phone call with four integers: Source, Destination, Start, and Duration. Source and Destination are integers with $0 \le \text{Source}, \text{Destination} \le 10{,}000{,}000$. Duration is the length of the call in seconds ($1 \le \text{Duration} \le 10{,}000$) and Start is the time the call begins ($\text{Start} \ge 0$). Every sum of Start and Duration fits in a signed 32-bit integer.

Each of the next $M$ lines describes one interval the police want to wiretap, given by two integers Start and Duration.

The input ends with a line containing two zeros ($N = M = 0$).

Output

For each test case, and for each interval, print the number of phone calls that fall within that interval, one per line. A phone call falls within an interval if the call and the interval overlap by at least $1$ second.