Implement hashCode, equals, and toString for Pair and Triple