N, Q, A, B, C, D, E, F, G = gets.split.map(&:to_i)

row = (D..E).to_a
col = (F..G).to_a

op = []
Q.times do
    c, i, j, x, y = gets.chomp.split
    op << [c, i.to_i, j.to_i, x.to_i, y.to_i]
end

update = []
op.reverse.each do |c, i, j, x, y|
    case c
    when 'WR'
        update.unshift [c, i, j, x, nil]
    when 'CP'
        update.unshift [c, i, j, x, y]
    when 'RV'
        col.map! {|c| N + 1 - c}
        update.each do |u|
            u[2] = N + 1 - u[2]
            u[4] = N + 1 - u[4] if u[0] == 'CP'
        end
    when 'RH'
        row.map! {|r| N + 1 - r}
        update.each do |u|
            u[1] = N + 1 - u[1]
            u[3] = N + 1 - u[3] if u[0] == 'CP'
        end
    when 'RL'
        row, col = col.map {|c| N + 1 - c}, row
        update.each do |u|
            u[1], u[2] = N + 1 - u[2], u[1]
            u[3], u[4] = N + 1 - u[4], u[3] if u[0] == 'CP'
        end
    when 'RR'
        row, col = col, row.map {|r| N + 1 - r}
        update.each do |u|
            u[1], u[2] = u[2], N + 1 - u[1]
            u[3], u[4] = u[4], N + 1 - u[3] if u[0] == 'CP'
        end
    when 'SR'
        h = {i => j, j => i}
        row.map! {|r| h[r] || r}
        update.each do |u|
            u[1] = h[u[1]] || u[1]
            u[3] = h[u[3]] || u[3] if u[0] == 'CP'
        end
    when 'SC'
        h = {i => j, j => i}
        col.map! {|c| h[c] || c}
        update.each do |u|
            u[2] = h[u[2]] || u[2]
            u[4] = h[u[4]] || u[4] if u[0] == 'CP'
        end
    end
end


target = []
hash = {}
row.each do |r|
    col.each do |c|
        k = [r, c]
        v = (A * r + B * c) % C
        target << k
        hash[k] = v
    end
end

update.each do |c, i, j, x, y|
    if c == 'WR'
        hash[[i, j]] = x
    else
        hash[[x, y]] = (hash[[i, j]] ||= (A * i + B * j) % C)
    end
end

h = 314159265
target.each do |k|
    h = (h * 31 + hash[k]) % 1_000_000_007
end
p h