For Windows :
After entering your license key and activation, your Windows is automatically linked to your computer's Mac address. Microsoft creates a profile of your device. On the basis of this data, a new installation checks whether your device was already equipped (with an activated version) with Windows 10. You can then reinstall it as much as you want on the same computer. You cannot use the license key on another PC.
For Office :
This depends on the license type. Check the product description to see if the product is suitable for account installation or valid for 1 PC or installation only.
You create an Office account at https://setup.office.com and enter your license key. After this, your product will always be present in your Microsoft Account. You can check this by going to https://account.microsoft.com/ and clicking on 'services and subscriptions' at the top of the menu, then you will find your product and you can install it again. Attention, only 1 installation is possible, so you first have to uninstall your installation on the other computer.
Attention : your original license key will no longer work if it is linked to your Microsoft Account and Microsoft will not allow a second use. You must therefore use your account for the reinstallation.
Attention, if you did not create a Microsoft Account or you bought a license without an account, you also cannot use your license key again to reinstall or activate !