P-Broken-Line

No attempts yetTime limit3sMemory limit512 MB

Problem

In the Cartesian plane, a point whose two coordinates are both integers is called a p-point. A p-segment is a closed line segment that is parallel to one of the coordinate axes and whose two endpoints are distinct p-points. A polyline made of kk p-segments in which every two consecutive segments are perpendicular is called a p-broken-line of degree kk.

You are given several p-segments together with two distinct p-points AA and BB. Find the smallest degree of a p-broken-line that joins AA and BB and shares no common point with any of the given p-segments, or determine that no such p-broken-line exists.

The vertices of the p-broken-line may be any p-points and are not restricted to the coordinates that appear in the input. Sharing a point is forbidden even at an endpoint of a p-segment, so the p-broken-line must stay completely off every given p-segment.

Input

The first line contains two integers xx and yy (0x,y1090 \le x, y \le 10^9), the coordinates of p-point AA. The second line contains the coordinates of p-point BB in the same format. The third line contains one integer nn (1n501 \le n \le 50), the number of p-segments. Each of the next nn lines contains four integers x1 y1 x2 y2x_1\ y_1\ x_2\ y_2, the coordinates of the two endpoints of one p-segment. Every p-segment is parallel to a coordinate axis and its two endpoints are distinct.

Output

Print a single line with the minimum degree of a p-broken-line that connects AA and BB and shares no point with any given p-segment. If no such p-broken-line exists, print the word BRAK instead.