When writing ordinal numbers such as 1st, 2nd, 3rd, etc. you should use the last two letters on the word as it would be if you wrote out the whole word. Below are the ordinal numbers both written out and with digits for 1-20.
As you can see, 1st, 2nd, and 3rd use -st, -nd, and -rd, but 4th-20th use -th. Follow this pattern for the numbers moving forward:
21st, 31st, 41st, etc. all use -st like 1st.
22nd, 32nd, 42nd, etc. all use -nd like 2nd.
23rd, 33rd, 43rd, etc. all use -rd like 3rd.
All the rest use -th (24th, 37th, 49th, 50th, 68th, 126th…).
I hope this helps.