def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]); ptr += 1 S = int(input[ptr]); ptr += 1 X = int(input[ptr]); ptr += 1 Y = int(input[ptr]); ptr += 1 Z = int(input[ptr]); ptr += 1 # Generate A_bit (1-based) A = [0] * (N + 1) A[1] = S % Z for i in range(2, N + 1): A[i] = (X * A[i-1] + Y) % Z A_bit = [a % 2 for a in A] C = [0] * (N + 1) # 1-based Q = int(input[ptr]); ptr += 1 for _ in range(Q): S_op = int(input[ptr]); ptr += 1 T_op = int(input[ptr]); ptr += 1 U = int(input[ptr]); ptr += 1 V = int(input[ptr]); ptr += 1 L = T_op - S_op + 1 # Check if the source and destination ranges overlap overlap = not (T_op < U or S_op > V) # Compute B_temp if overlap: B_temp = [] for i in range(S_op, T_op + 1): B_temp.append(A_bit[i] ^ C[i]) else: B_temp = [A_bit[i] ^ C[i] for i in range(S_op, T_op + 1)] # Apply B_temp to destination range U..V for j in range(U, V + 1): idx = j - U C[j] ^= B_temp[idx] # Generate the result res = [] for i in range(1, N + 1): res.append('E' if (A_bit[i] ^ C[i]) == 0 else 'O') print(''.join(res)) if __name__ == '__main__': main()