Sponsored
Use these hints if you're stuck. Try solving on your own first.
Consider the graphs where each pair in "pairs" is an edge. Two words are similar if they are the same, or are in the same connected component of this graph.
Solve with full IDE support and test cases