It's the last question of a pattern matching IQ-test. Just google images for "iq test pattern". The logic can be just about anything.