T = int(input()) ans = [] for _ in range(T): C = list(map(int, input().split())) H = list(map(int, input().split())) for i in range(0,C[1]): if max(H[0:C[1]-1]) != H[0] | max(H[C[0]-C[1]]) != H[C[0]-1]: ans.append("No") break M = [] for i in range(0,len(H)): M.append(H[i]%C[2]) for i in range(1, len(C)): if M[i] == M[0]: continue else: ans.append("No") break else: ans.append("Yes") for i in range(0,len(ans)): print(ans[i])