On a two-dimensional plane, there are L-shaped obstacles whose sides are parallel to the coordinate axes. The obstacles do not overlap, and they do not touch one another at edges or vertices.
A robot wants to move from a start point to a fixed destination while avoiding the obstacles. The robot can move only in directions parallel to the coordinate axes, and it may move along the boundary of an obstacle. The robot's size is ignored, so it can be treated as a point on the plane. The start and destination points are never inside an obstacle and are never on an obstacle boundary.
The following picture shows that there may be several paths to the destination. In this case, the minimum possible number of turns is 3.

Given the L-shaped obstacles, the start point, and the destination point, find the minimum number of turns among all valid paths from the start to the destination.
The first line gives the coordinates of the robot's start point. The second line gives the coordinates of the destination point. The third line gives the number of obstacles (N), where (N \le 50).
Each of the next (N) lines gives four points (p_1, p_2, p_3, p_4) that describe one obstacle. Each point is written as x y, so one obstacle is represented by 8 integers. The relative positions of the four points are shown below.

Every coordinate value is a natural number at most 100.
Print the minimum number of turns among all paths that move the robot from the start point to the destination point.