public static void main ( String [ ] args ) throws IOException {
  FastReader sc = new FastReader ( ) ;
  PrintWriter out = new PrintWriter ( System . out ) ;
  int n = sc . nextInt ( ) , m = sc . nextInt ( ) ;
  int x = sc . nextInt ( ) , y = sc . nextInt ( ) ;
  int k = sc . nextInt ( ) ;
  int r = Math . max ( n , m ) ;
  long count = 0 ;
  while ( k -- > 0 ) {
    int dx = sc . nextInt ( ) , dy = sc . nextInt ( ) ;
    int movx = Integer . MAX_VALUE ;
    int movy = Integer . MAX_VALUE ;
    if ( dx < 0 ) movx = ( 1 - x ) / dx ;
    else if ( dx > 0 ) movx = ( n - x ) / dx ;
    if ( dy < 0 ) movy = ( 1 - y ) / dy ;
    else if ( dy > 0 ) movy = ( m - y ) / dy ;
    int min = Math . min ( movx , movy ) ;
    count += min ;
    x += dx * min ;
    y += dy * min ;
  }
  out . println ( count ) ;
  out . close ( ) ;
}

public static void main ( String [ ] args ) throws IOException { FastReader sc = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int x = sc . nextInt ( ) , y = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int r = Math . max ( n , m ) ; long count = 0 ; while ( k -- > 0 ) { int dx = sc . nextInt ( ) , dy = sc . nextInt ( ) ; int movx = Integer . MAX_VALUE ; int movy = Integer . MAX_VALUE ; if ( dx < 0 ) movx = ( 1 - x ) / dx ; else if ( dx > 0 ) movx = ( n - x ) / dx ; if ( dy < 0 ) movy = ( 1 - y ) / dy ; else if ( dy > 0 ) movy = ( m - y ) / dy ; int min = Math . min ( movx , movy ) ; count += min ; x += dx * min ; y += dy * min ; } out . println ( count ) ; out . close ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))