Hello!
Few places depending on your setup.
1. If you have your contacts and other "sync capable" selections setup to backup to your Google account then its stored on Google's services. THIS IS HIGHLY RECOMMENDED
2. If you have things setup to only store to your device then you have to off load your contacts, etc using the EXPORT option from within the app. Contacts or " PEOPLE " is one that offers this.
Once you do a factory reset, reboot and log back into your device it will ask you during the setup wizard if you want to retrieve your info (if you have it synced to Google). Also under your Settings/Backup & Reset/ make sure you have it properly selected here also before doing the factory reset.
There is also the use of HTC Sync that allows things to be backed up to computer, but to be honest I have never used it. I rather use Google's backup which has never failed me and is the preferred method of keeping important info like your contacts safe.