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

queries = (1..q).map do
    c, i, j, x, y = gets.chomp.split
    [c, i.to_i, j.to_i, x.to_i, y.to_i]
end

#contract rotation, reflection

contracted = []
mirror = false
rot = 0

def trans(mirror, rot, n, r, c)
    rot.times { r, c = n + 1 - c, r }
    c = n + 1 - c if mirror
    return [r, c]
end

queries.each do |query|
    case query[0]
    when 'WR'
        _, r, c, v = query
        r, c = trans(mirror, rot, n, r, c)
        contracted << ['WR', r, c, v]
    when 'CP'
        _, r1, c1, r2, c2 = query
        r1, c1 = trans(mirror, rot, n, r1, c1)
        r2, c2 = trans(mirror, rot, n, r2, c2)
        contracted << ['CP', r1, c1, r2, c2]
    when 'SR'
        _, r1, r2 = query
        if rot.even?
            r1, _ = trans(mirror, rot, n, r1, 0)
            r2, _ = trans(mirror, rot, n, r2, 0)
            contracted << ['SR', r1, r2]
        else
            _, c1 = trans(mirror, rot, n, r1, 0)
            _, c2 = trans(mirror, rot, n, r2, 0)
            contracted << ['SC', c1, c2]
        end
    when 'SC'
        _, c1, c2 = query
        if rot.odd?
            r1, _ = trans(mirror, rot, n, 0, c1)
            r2, _ = trans(mirror, rot, n, 0, c2)
            contracted << ['SR', r1, r2]
        else
            _, c1 = trans(mirror, rot, n, 0, c1)
            _, c2 = trans(mirror, rot, n, 0, c2)
            contracted << ['SC', c1, c2]
        end
    when 'RL'
        rot = (rot - 1) % 4
    when 'RR'
        rot = (rot + 1) % 4
    when 'RH'
        mirror = ! mirror
        rot = (rot + 2) % 4 if rot.even?
    when 'RV'
        mirror = ! mirror
        rot = (4 - rot) % 4
    end
end

queries = contracted
contracted = []

#contract swap

row_perm = (0..n).to_a
col_perm = (0..n).to_a
row_perm_inv = (0..n).to_a
col_perm_inv = (0..n).to_a

queries.each do |query|
    case query[0]
    when 'WR'
        _, r, c, v = query
        r = row_perm_inv[r]
        c = col_perm_inv[c]
        contracted << ['WR', r, c, v]
    when 'CP'
        _, r1, c1, r2, c2 = query
        r1 = row_perm_inv[r1]
        c1 = col_perm_inv[c1]
        r2 = row_perm_inv[r2]
        c2 = col_perm_inv[c2]
        contracted << ['CP', r1, c1, r2, c2]
    when 'SR'
        _, r1, r2 = query
        row_perm[r1], row_perm[r2] = row_perm[r2], row_perm[r1]
        row_perm_inv[row_perm[r1]] = r1
        row_perm_inv[row_perm[r2]] = r2
    when 'SC'
        _, c1, c2 = query
        col_perm[c1], col_perm[c2] = col_perm[c2], col_perm[c1]
        col_perm_inv[col_perm[c1]] = c1
        col_perm_inv[col_perm[c2]] = c2
   end
end

row = (D..E).to_a
col = (F..G).to_a
rot.times do
    row, col = col.map {|c| n + 1 - c}, row
end
col.map! {|c| n + 1 - c} if mirror
row.map! {|r| row_perm_inv[r]}
col.map! {|c| col_perm_inv[c]}

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

contracted.each do |query|
    case query[0]
    when 'WR'
        _, r, c, v = query
        hash[[r, c]] = v
    when 'CP'
        _, r1, c1, r2, c2 = query
        hash[[r2, c2]] = (hash[[r1, c1]] ||= (r1 * A + c1 * B) % C)
    end
end

h = 314159265
if rot.even?
    row.each do |r|
        col.each do |c|
            h = (h * 31 + hash[[r, c]]) % 1_000_000_007
        end
    end
else
    col.each do |c|
        row.each do |r|
            h = (h * 31 + hash[[r, c]]) % 1_000_000_007
        end
    end
end
p h