#K82997. Minimal Unique Ingredients

    ID: 36099 Type: Default 1000ms 256MiB

Minimal Unique Ingredients

Minimal Unique Ingredients

You are given several test cases. In each test case, you have a number of recipes. Each recipe is a string of space-separated ingredients. Your task is to determine the minimal set of unique ingredients needed to prepare all recipes in each test case. The resulting set must be sorted in alphabetical order.

For example, if the recipes are "salt pepper", "chicken garlic salt" and "lemon chicken", the minimal unique set of ingredients is "chicken garlic lemon pepper salt".

Output the result for each test case on a separate line.

inputFormat

The input is given via standard input (stdin) with the following format:

  • The first line contains an integer T representing the number of test cases.
  • For each test case:
    • The first line contains an integer N representing the number of recipes.
    • Then follow N lines each containing a recipe (a string of space-separated ingredients).

outputFormat

For each test case, print a single line (to standard output stdout) containing the minimal set of unique ingredients needed to prepare all recipes, sorted in alphabetical order and separated by a single space.

## sample
2
3
salt pepper
chicken garlic salt
lemon chicken
2
butter sugar flour
milk butter
chicken garlic lemon pepper salt

butter flour milk sugar

</p>