Water pipe

No attempts yetTime limit1sMemory limit128 MB

Problem

The city of Eastowner is perpetually plagued by water shortages, so a new water pipe is being built. Construction started from both ends at the same time, and the two halves were finally joined — almost. The first half ends at point (x1,y1)(x_1, y_1) and the second half ends at point (x2,y2)(x_2, y_2). Only a few leftover pipe segments of various lengths are available. Because of the peculiarities of local technology, each segment may be laid only in the north–south or the east–west direction, and two segments may be connected only so that they continue in a straight line or make a 9090^\circ turn (a 180180^\circ U-turn is not allowed).

Given the available segment lengths L1,,LkL_1, \dots, L_k and the number of segments CiC_i of each length LiL_i, construct a pipe that connects (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), or report that it is impossible. Output the minimum number of segments required.

Input

The input contains the integers x1 y1 x2 y2 kx_1\ y_1\ x_2\ y_2\ k, followed by 2k2k integers L1 L2  Lk C1 C2  CkL_1\ L_2\ \dots\ L_k\ C_1\ C_2\ \dots\ C_k. The values are separated by whitespace (spaces or newlines).

Output

Output a single integer — the minimum number of segments required, or 1-1 if the connection is impossible.

Constraints

  • 1k41 \le k \le 4
  • 1xi,yi,Li10001 \le x_i, y_i, L_i \le 1000
  • 1Ci101 \le C_i \le 10