import sys t=sys.stdin.read() T=t.split("\n") w=T[0] for l in T[1:]: if sorted(list(l))==sorted(list(w)):print l