Similar Items: First-Order and Temporal Logics for Nested Words