You have to essentially work backward. So check for the last interface, and if false, check for the 2nd to last interface, and if false, check for the 2nd interface, and if false, check for the first interface.
And obviously if true, interact with said interface with the necessary actions.