H,N=(int(i) for i in input().split()) c=0 for i in range(N): g=int(input()) if g>H: c+=1 S=str(g) S=S[-1] if S=="1": d="st" elif S=="2": d=="nd" elif S=="3": d=="rd" else: d=="th" print(S+d)