Because the permutation p is selected uniformly and randomly, the permutations of matrices (X_{i, j}) and (X_{i, j}) are identically distributed. In this way, we know that the expectation of z is the sum of the elements of the upper and lower triangular arrays (all without diagonal lines) in (X_{i, j}), and the expectation is 1/2 times. Because of the nature of permutation, the diagonal elements of (X_{i, j}) must all be 0. So the expectation of z is 1/2 times the expectation of the sum of all the elements in (X_{i, j}).
Due to the nature of permutation, the sum of all elements in the corresponding matrix (X_{i, j}) is n(n- 1)/2 (so the expectation of the sum of all elements in (X_{i, j}) is also n(n- 1)/2).
I think the first question of this question can be thought as follows: first try to list the cases where n=2 (in fact, write two (X_{i, j}) matrices). If you have no clue, try n=3(6 matrices).