public static void main ( String [ ] $ ) {
  int n = scanner . nextInt ( ) , a = scanner . nextInt ( ) - 1 , b = scanner . nextInt ( ) - 1 , m = scanner . nextInt ( ) , aa [ ] [ ] = new int [ n ] [ n ] , ba [ ] [ ] = new int [ n ] [ n ] , ca [ ] [ ] = new int [ n ] [ n ] ;
  for ( int i = 0 , l , r ;
  i < m ;
  i ++ ) aa [ l = scanner . nextInt ( ) - 1 ] [ r = scanner . nextInt ( ) - 1 ] = aa [ r ] [ l ] = ba [ l ] [ r ] = ba [ r ] [ l ] = 1 ;
  System . out . println ( IntStream . range ( 0 , n ) . reduce ( 0 , ( a1 , b1 ) -> {
    if ( ba [ a ] [ b ] != 0 ) return ba [ a ] [ b ] ;
    IntStream . range ( 0 , n ) . forEach ( i -> IntStream . range ( 0 , n ) . forEach ( j -> ca [ i ] [ j ] = IntStream . range ( 0 , n ) . map ( k -> ba [ i ] [ k ] * aa [ k ] [ j ] ) . sum ( ) % mod ) ) ;
    IntStream . range ( 0 , n ) . forEach ( i -> IntStream . range ( 0 , n ) . forEach ( j -> ba [ i ] [ j ] = ca [ i ] [ j ] ) ) ;
    return ba [ a ] [ b ] ;
  }
  ) ) ;
}

public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) , a = scanner . nextInt ( ) - 1 , b = scanner . nextInt ( ) - 1 , m = scanner . nextInt ( ) , aa [ ] [ ] = new int [ n ] [ n ] , ba [ ] [ ] = new int [ n ] [ n ] , ca [ ] [ ] = new int [ n ] [ n ] ; for ( int i = 0 , l , r ; i < m ; i ++ ) aa [ l = scanner . nextInt ( ) - 1 ] [ r = scanner . nextInt ( ) - 1 ] = aa [ r ] [ l ] = ba [ l ] [ r ] = ba [ r ] [ l ] = 1 ; System . out . println ( IntStream . range ( 0 , n ) . reduce ( 0 , ( a1 , b1 ) -> { if ( ba [ a ] [ b ] != 0 ) return ba [ a ] [ b ] ; IntStream . range ( 0 , n ) . forEach ( i -> IntStream . range ( 0 , n ) . forEach ( j -> ca [ i ] [ j ] = IntStream . range ( 0 , n ) . map ( k -> ba [ i ] [ k ] * aa [ k ] [ j ] ) . sum ( ) % mod ) ) ; IntStream . range ( 0 , n ) . forEach ( i -> IntStream . range ( 0 , n ) . forEach ( j -> ba [ i ] [ j ] = ca [ i ] [ j ] ) ) ; return ba [ a ] [ b ] ; } ) ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) 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: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (identifier)))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (identifier)))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (assignment_expression left: (identifier) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) index: (assignment_expression left: (identifier) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) right: (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) name: (identifier) arguments: (argument_list (decimal_integer_literal) (lambda_expression parameters: (inferred_parameters (identifier) (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (decimal_integer_literal))) consequence: (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (expression_statement (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) name: (identifier) arguments: (argument_list (lambda_expression parameters: (identifier) body: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) name: (identifier) arguments: (argument_list (lambda_expression parameters: (identifier) body: (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (binary_expression left: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) name: (identifier) arguments: (argument_list (lambda_expression parameters: (identifier) body: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))) name: (identifier) arguments: (argument_list)) right: (identifier)))))))))) (expression_statement (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) name: (identifier) arguments: (argument_list (lambda_expression parameters: (identifier) body: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) name: (identifier) arguments: (argument_list (lambda_expression parameters: (identifier) body: (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))))))) (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))))))))))))