select kth element in a matrix