Since I did most of my beer-drinking at home, instead of at a uni, I'm not sure either, but I'm very sure I could solve it, and you can too.
Sometimes, you get to use a handy map to find your way around, and sometimes you have to just use the environment and "just fly the plane". This is the latter case. You will learn how to do it, by doing it. ;)
I'd start with making a struct for each row, with the state, the input a, and the input b, and sort them with input a and input b as keys (that is, if a's are tied, in two structs as you sort, then sort by input b to reach the sorted position. Now you're ready to go on your first matching input "hunt".
Take it step by step to cut the problem down to size. Use a paper and pen if you can't see your way through it yet. Start ASAP, because it always takes longer when you don't have a map to help out.