If you fail your IPPT this window and didn't clear the 10 sessions IPT, you will need to attend 20 sessions of RT next window. But the 20 sessions will minus the number of IPPT attempts you have taken this window. So for example, if you have attempted 3 IPPTs, it will be 20-3=17.
As for IPT, as long as you completed the 10 required sessions, you are considered cleared for the window - meaning to say you don't have to take RT the next window. But if you didn't passed your IPPT and didn't managed to clock 10 sessions of IPT, you will still need to attend RT the next window less the number of IPTs attended. So for example, if you attended only 7 IPTs instead of 10, you will need to attend 20-7=13 RTs the next window.
And take note that for RT, it is always to pay back your 'debt' for the last window. So you will still need to clear your current window (either by passing IPPT or IPT) even after finishing your RT.