public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  PrintWriter pw = new PrintWriter ( System . out ) ;
  int N = sc . nextInt ( ) ;
  int M = sc . nextInt ( ) ;
  int [ ] a = new int [ M ] ;
  int [ ] b = new int [ M ] ;
  for ( int i = 0 ;
  i < M ;
  i ++ ) {
    a [ i ] = sc . nextInt ( ) - 1 ;
    b [ i ] = sc . nextInt ( ) - 1 ;
  }
  int MAXD = 10 ;
  int [ ] [ ] dp = new int [ N ] [ MAXD + 1 ] ;
  int Q = sc . nextInt ( ) ;
  int [ ] c = new int [ Q + 1 ] ;
  for ( int i = 0 ;
  i < Q ;
  i ++ ) {
    int v = sc . nextInt ( ) - 1 ;
    int d = sc . nextInt ( ) ;
    c [ i + 1 ] = sc . nextInt ( ) ;
    dp [ v ] [ d ] = Math . max ( dp [ v ] [ d ] , i + 1 ) ;
  }
  for ( int i = MAXD ;
  i > 0 ;
  i -- ) {
    for ( int j = 0 ;
    j < M ;
    j ++ ) {
      dp [ a [ j ] ] [ i - 1 ] = Math . max ( dp [ a [ j ] ] [ i - 1 ] , dp [ b [ j ] ] [ i ] ) ;
      dp [ b [ j ] ] [ i - 1 ] = Math . max ( dp [ b [ j ] ] [ i - 1 ] , dp [ a [ j ] ] [ i ] ) ;
    }
    for ( int j = 0 ;
    j < N ;
    j ++ ) {
      dp [ j ] [ i - 1 ] = Math . max ( dp [ j ] [ i - 1 ] , dp [ j ] [ i ] ) ;
    }
  }
  for ( int i = 0 ;
  i < N ;
  i ++ ) pw . println ( c [ dp [ i ] [ 0 ] ] ) ;
  sc . close ( ) ;
  pw . close ( ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] a = new int [ M ] ; int [ ] b = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { a [ i ] = sc . nextInt ( ) - 1 ; b [ i ] = sc . nextInt ( ) - 1 ; } int MAXD = 10 ; int [ ] [ ] dp = new int [ N ] [ MAXD + 1 ] ; int Q = sc . nextInt ( ) ; int [ ] c = new int [ Q + 1 ] ; for ( int i = 0 ; i < Q ; i ++ ) { int v = sc . nextInt ( ) - 1 ; int d = sc . nextInt ( ) ; c [ i + 1 ] = sc . nextInt ( ) ; dp [ v ] [ d ] = Math . max ( dp [ v ] [ d ] , i + 1 ) ; } for ( int i = MAXD ; i > 0 ; i -- ) { for ( int j = 0 ; j < M ; j ++ ) { dp [ a [ j ] ] [ i - 1 ] = Math . max ( dp [ a [ j ] ] [ i - 1 ] , dp [ b [ j ] ] [ i ] ) ; dp [ b [ j ] ] [ i - 1 ] = Math . max ( dp [ b [ j ] ] [ i - 1 ] , dp [ a [ j ] ] [ i ] ) ; } for ( int j = 0 ; j < N ; j ++ ) { dp [ j ] [ i - 1 ] = Math . max ( dp [ j ] [ i - 1 ] , dp [ j ] [ i ] ) ; } } for ( int i = 0 ; i < N ; i ++ ) pw . println ( c [ dp [ i ] [ 0 ] ] ) ; sc . close ( ) ; pw . close ( ) ; }
(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: (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: (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)))) (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) (array_access array: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) index: (identifier)))))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) (array_access array: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) index: (identifier)))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))