5
10
bb
bb
ab
aa
bb
bb
ba
aa
bb
ab
10
bb
ab
ba
ab
ba
ba
ab
ba
ba
ba
10
aa
ba
ba
ba
bb
ab
ab
aa
bb
bb
10
ab
ab
bb
bb
ab
ba
aa
ba
ab
aa
10
ba
bb
bb
bb
aa
ba
ba
ba
bb
bb
aa
ab
ba
bb
ab
ba
bb
aa
ab
ba
bb
aa
ab
ba
bb
aa
ba
bb

# import modules used here -- sys is a very standard one
import sys

class Node:
	def __init__(self, val):
		self.val = val
		self.right = None
		self.left = None
		
	def insert(self, val):
		if (val < self.val):
			if (self.left == None):
				self.left = Node(val)
			else:
				self.left.insert(val)
		elif (val > self.val):
			if (self.right == None):
				self.right = Node(val)
			else:
				self.right.insert(val)
		else:
			pass

	def printTree(self):
		if (self.left != None):
			self.left.printTree()
		print self.val
		if (self.right != None):
			self.right.printTree()

# Gather our code in a main() function
def main():
	totalTestCount = raw_input()
	i = 0
	while (i < int(totalTestCount)):
		totalNamesInEachTest = raw_input()
		inviteList = []
		j = 0
		root = Node(raw_input())
  		while (j < int(totalNamesInEachTest) -1):
  			root.insert(raw_input())
			j=j+1
		root.printTree()
		i=i+1

# Standard boilerplate to call the main() function to begin
# the program.
if __name__ == '__main__':
    main()