Format, clean install, & restore iPhone 3GS
Connect the device to iTunes and click Back Up Device.
Once the backup is complete, click Restore iPhone and follow the instructions to restore iOS on your iPhone.
Once this is complete, iTunes will prompt you to restore your backup which will restore all your data back to your device. All your data will be restored to your device except account passwords unless your backup is encrypted.