Samsung
From Settings, swipe to and tap Accounts and backup.
Tap Manage accounts, and then select your Samsung account.
Tap Remove account, and then tap Remove account on the popup.
Tap Sign out. Enter your Samsung account password, and then tap OK.
From Settings, swipe to and tap Accounts and backup.
Tap Manage accounts, and then select your Google account.
Tap Remove account, and then tap Remove account again to confirm.
If you have Google device protection features enabled, you may be asked to verify your identity before you can fully log out of your account.