Based on your explanation, I'm not sure that I can find a solution because of the increasing number of variables that have to be taken into account. If there could be a way of simplifying the process, then perhaps I could come up with something.