import sys def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]); ptr +=1 Q = int(input[ptr]); ptr +=1 P = int(input[ptr]); ptr +=1 A = list(map(int, input[ptr:ptr+N])); ptr +=N # Precompute for each position s, the closure set for ranges [s, e] # We can precompute for each s, up to e_max(s) where adding more elements doesn't change the closure # But for now, we'll process each query on the fly due to time constraints. for _ in range(Q): L = int(input[ptr])-1; ptr +=1 R = int(input[ptr])-1; ptr +=1 K = int(input[ptr]); ptr +=1 if K == 0: # Check if any element in A[L:R+1] is zero if any(x == 0 for x in A[L:R+1]): print("Yes") else: print("No") continue # Extract non-zero elements non_zero = [x for x in A[L:R+1] if x != 0] if not non_zero: print("No") continue possible = set() found = False for num in non_zero: new_products = set() new_products.add(num % P) for p in possible: new_p = (p * num) % P new_products.add(new_p) possible.update(new_products) if K in possible: found = True break if found: print("Yes") else: print("No" if K not in possible else "Yes") if __name__ == "__main__": main()