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