Error with cin.getline and while loop

The code to remove duplicates takes input when there is only one test case


But when there are multiple test cases,
I am getting a segmentation error and cant take the input.

Plz use cin instead of cin.getline and also in the question, you are not supposed to take the no of test cases. So plz avoid using that

Hello ,
There is no question to begin with in the course.
Like I have mentioned I need multiple test cases and the input has " multiple words" .

Again clarifying , it’s not about any question in the course and completely conceptual.

I am not able to get your point correctly.