Very easy.
Make 4 or more versions of each ability. Give each version different hotkey (q,w,e, r, d, f)(or whatever).
If it's the first ability the unit is learning, give it the Q version. If it's the second - W version.
For player's comfort make a command to change them like "-swapspell qw" or somthing like that.