Watches
A client, who appears to be a private detective, has brought a severely damaged watch to the repair shop. Not only has the watch stopped, but paint has also been spilled over it, obscuring part of the dial. The client has asked you to figure out the time at which the watch stopped. Since the entire dial isn't visible, you and the client have decided to calculate the number of possible positions the hands could have been in when the watch stopped.
The watch dial is a circle divided into minute increments, ranging from 0 to 59. The watch features only an hour hand and a minute hand, with each hand precisely aligned with one of these divisions at any given time. Each hour is represented by 5 divisions. Specifically, from the 0th to the 11th minute, the hour hand is on the first division of the hour; from the 12th to the 23rd minute, it's on the second; from the 24th to the 35th minute, it's on the third; from the 36th to the 47th minute, it's on the fourth; and from the 48th to the 59th minute, it's on the fifth. For instance, at 3:30, the minute hand is on the 30th division, and the hour hand is on the 17th.
Due to the paint, only a portion of the dial within a specific sector is visible. Your task is to determine how many different positions the hands could have been in when the watch stopped.
The image illustrates the queries from the example.
Input
The first line contains the number of queries q (1 ≤ q ≤ 1000). Each query is provided on a separate line.
Each query consists of four integers a, b, h, and m, separated by spaces (0 ≤ a, b ≤ 59). These integers define the visible segment of the dial, where the minute hand moves from the a-th to the b-th minute, inclusive. If a ≤ b, the visible segment is [a, b]. If b < a, the visible segment is [a, 59] ∪ [0, b].
The integer h indicates the position of the hour hand. If h = −1, the hour hand is not visible. Otherwise, h is within the visible segment from a to b. Similarly, m indicates the position of the minute hand.
Output
For each query, output a single integer on a separate line, representing the number of possible positions the hands could have been in when the watch stopped.