One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.

Vasya noticed that the yard is a rectangular n × m field. The squares have coordinates (x, y) (1 ≤ x ≤ n, 1 ≤ y ≤ m), where x is the index of the row and y is the index of the column.

Initially Vasya stands in the square with coordinates (xc, yc). To play, he has got a list of k vectors (dxi, dyi) of non-zero length. The game goes like this. The boy considers all vectors in the order from 1 to k, and consecutively chooses each vector as the current one. After the boy has chosen a current vector, he makes the maximally possible number of valid steps in the vector's direction (it is possible that he makes zero steps).

A step is defined as one movement from the square where the boy is standing now, in the direction of the current vector. That is, if Vasya is positioned in square (x, y), and the current vector is (dx, dy), one step moves Vasya to square (x + dx, y + dy). A step is considered valid, if the boy does not go out of the yard if he performs the step.

Vasya stepped on and on, on and on until he ran out of vectors in his list. Ha had been stepping for so long that he completely forgot how many steps he had made. Help the boy and count how many steps he had made.

Input

The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m).

The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two integers dxi and dyi (|dxi|, |dyi| ≤ 109, |dx| + |dy| ≥ 1).

Output

Print the single number — the number of steps Vasya had made.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Examples

Input

4 5
1 1
3
1 1
1 1
0 -2


Output

4


Input

10 10
1 2
1
-1 0


Output

0

Note

In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall, Vasya makes 4 steps.

In the second sample Vasya is initially positioned in square (1, 2) and makes 0 steps by vector ( - 1, 0), as the square with coordinates (0, 2) is located outside the yard.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

    static class Utils {
        public static final Random rand = new Random();

        public static void initArray(int[] a, int value) {
            for (int i = 0; i < a.length; i++) {
                a[i] = value;
            }
        }

        public static void initArrayPositiv(int[] a) {
            for (int i = 0; i < a.length; i++) {
                a[i] = i;
            }
        }

        public static int maxValueInArray(int[] a) {
            if (a == null || a.length == 0)
                return 0;
            int max = a[0];
            for (int i = 1; i < a.length; i++) {
                if (max < a[i])
                    max = a[i];
            }
            return max;
        }

        public static int minValueInArray(int[] a) {
            if (a == null || a.length == 0)
                return 0;
            int min = a[0];
            for (int i = 1; i < a.length; i++) {
                if (min > a[i])
                    min = a[i];
            }
            return min;
        }

        public static int maxValueIndexInArray(int[] a) {
            if (a == null || a.length == 0)
                return 0;
            int index = 0;
            for (int i = 1; i < a.length; i++) {
                if (a[index] < a[i])
                    index = i;
            }
            return index;
        }

        public static int minValueIndexInArray(int[] a) {
            if (a == null || a.length == 0)
                return 0;
            int index = 0;
            for (int i = 1; i < a.length; i++) {
                if (a[index] > a[i])
                    index = i;
            }
            return index;
        }

        public static List<Integer> getDivs(long v) {
            List<Integer> result = new ArrayList<Integer>();
            int p = (int) (Math.sqrt(v) + 1);
            for (int i = 0; i < p; i++) {
                if (v % i == 0) {
                    result.add(i);
                }
            }
            return result;
        }

        public static boolean isPrime(long v) {
            int p = (int) (Math.sqrt(v) + 1);
            for (int i = 2; i < p; i++) {
                if (v % i == 0)
                    return false;
            }
            return true;
        }

        public static int[] prefixFunction(String s) {
            int n = (int) s.length();
            int pi[] = new int[n];
            for (int i = 1; i < n; ++i) {
                int j = pi[i - 1];
                while (j > 0 && s.charAt(i) != s.charAt(j))
                    j = pi[j - 1];
                if (s.charAt(i) == s.charAt(j))
                    ++j;
                pi[i] = j;
            }
            return pi;
        }
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    StringTokenizer str = null;
    BufferedReader in;
    PrintWriter out;

    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
        out.close();
    }

    String nextString() throws IOException {
        return in.readLine();
    }

    String nextToken() throws IOException {
        if (str == null || !str.hasMoreElements()) {
            str = new StringTokenizer(nextString());
        }
        return str.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int x0 = nextInt();
        int y0 = nextInt();
        int k = nextInt();
        long count = 0;
        for (int i = 0; i < k; i++) {
            int dx = nextInt();
            int dy = nextInt();
            if (dx == 0 && dy == 0) {
                continue;
            }
            if (dx == 0 || dy == 0) {

                if (dx == 0) {
                    int hy = 0;
                    if (dy > 0)
                        hy = (m - y0) / dy;
                    else
                        hy = (y0- 1) / Math.abs(dy);
                    count += hy;
                    y0 += dy * hy;
                }

                if (dy == 0) {
                    int hx = 0;
                    if (dx > 0)
                        hx = (n - x0) / dx;
                    else
                        hx = (x0 - 1) / Math.abs(dx);
                    count += hx;
                    x0 += dx * hx;
                }
                continue;
            }

            int hx = 0;
            int hy = 0;
            int min = 0;
            if (dx > 0)
                hx = (n - x0) / dx;
            else
                hx = (x0- 1) / Math.abs(dx);

            if (dy > 0)
                hy = (m - y0) / dy;
            else
                hy = (y0- 1) / Math.abs(dy);
            min = Math.min(hx, hy);
            count += min;
            x0 += dx * min;
            y0 += dy * min;
        }

        out.println(count);
    }
}