count your blessings. I remember years ago I applied for the job I have now, had two interviews, written test, got glowing recommendations and the manager hired someone external. 2 years later the guy they hired was leaving and I applied again . This time the former manager was gone and the role was now changed to a higher pay grade. I applied and during the interview the hiring manager said not wasting your time and just offered me the position.
Taught me a valuable lesson in life, if I was hired back then I might have failed working under that former manager, or if i was hired back then they never would have changed the role and I'd be making way less than I am right now.
yes being rejected sucks but sometimes its for the best.