Pins 1 through 4 are the rows, pins 5 through 8 are the columns. If pin 2 and pin 8 are connected then switch S8 is pressed.