You have 2 options:
1) Mass Planner with 2 modules: unlimited accounts and "Like & Comment". Total cost of the modules is ~ $80 (one-time fee) after discount. A MP license is $10/month or $7.5/month when you buy 6 months of subscription in advance. You are definitely going to need way more than 1 license to handle 5k accounts. The maximum I ever handled and what the developer team suggests is around 500, but I was doing a lot of actions with each account. It seems you will only do 1-2 accounts with each account, so maybe you can increase the number of accounts you can use on 1 license, but you will definitely experience lagging issues with the software UI as well. I suggest you test first on 1 licence, see the limits of the software for yourself for what you are trying to do and then calculate how many more licenses you need.
2) iMacros - free to use, but a pain in the ass to code the macros, especially without any programming background or experience.