avoid print subsegments by using a hashset. All test passed!