unpacked the number of rows & columns instead of putting them into an array
unpacking the query co-ordinates instead of using an array; reading in the entire input to speed up the run time; note that doing this instead of using raw_input uses three times as much of memory