#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef pair<int, int> P;
int N, Q;
int A, B, C;
int D, E, F, G;
int rot;
int revy;
int revx;
int row[40404];
int col[40404];
void get(int& x, int& y) {
    x--; y--;
    if(revy) y = N - 1 - y;
    if(revx) x = N - 1 - x;
    if(rot) swap(y, x);

    y = row[y];
    x = col[x];
}

int init(int x, int y) {
    return ((long long)(y + 1) * A + (long long)(x + 1) * B) % C;
}

void rotate() {
    rot ^= 1;
    bool nry = revx ^ 1;
    bool nrx = revy;
    revy = nry;
    revx = nrx;
}

int main(){
    while(cin >> N >> Q >> A >> B >> C >> D >> E >> F >> G) {

        rot = revx = revy = false;
        REP(i, N) row[i] = i;
        REP(i, N) col[i] = i;

        map<P, int> mat;

        auto get_value = [&](int x, int y, bool insert=true) {
            if(!mat.count(P(x, y))) {
                if(insert) {
                    mat[P(x, y)] = init(x, y);
                } else {
                    return init(x, y);
                }
            }
            return mat[P(x, y)];
        };

        REP(_, Q) {
            string s;
            cin >> s;
            //cout << s << "!" << endl;
            if(s == "WR") {
                int y, x, val;
                cin >> y >> x >> val;
                get(x, y);
                mat[P(x, y)] = val;
            } else if(s == "CP") {
                int y1, x1, y2, x2;
                cin >> y1 >> x1 >> y2 >> x2;
                get(x1, y1);
                get(x2, y2);
                mat[P(x2, y2)] = get_value(x1, y1);
            } else if(s == "SR") {
                int y1, y2;
                cin >> y1 >> y2;
                y1--; y2--;
                if(!rot) {
                    if(revy) y1 = N - 1 - y1;
                    if(revy) y2 = N - 1 - y2;
                    swap(row[y1], row[y2]);
                } else {
                    int x1 = y1, x2 = y2;
                    if(revy) x1 = N - 1 - x1;
                    if(revy) x2 = N - 1 - x2;
                    swap(col[x1], col[x2]);
                }
            } else if(s == "SC") {
                int x1, x2;
                cin >> x1 >> x2;
                x1--; x2--;
                if(rot) {
                    int y1 = x1, y2 = x2;
                    if(revx) y1 = N - 1 - y1;
                    if(revx) y2 = N - 1 - y2;
                    swap(row[y1], row[y2]);
                } else {
                    if(revx) x1 = N - 1 - x1;
                    if(revx) x2 = N - 1 - x2;
                    swap(col[x1], col[x2]);
                }
            } else if(s == "RL") {
                rotate();
            } else if(s == "RR") {
                REP(i, 3) rotate();
            } else if(s == "RH") {
                revy ^= 1;
            } else if(s == "RV") {
                revx ^= 1;
            } 
            // cerr << "rot: " << rot << endl;;
            // cerr << "revx: " << revx << endl;;
            // cerr << "revy: " << revy << endl;;
        }

        long long h = 314159265;
        const int MOD = 1000000007;
        // if(N < 10) {
        //     for(int y = 0; y < N; y++) {
        //         for(int x = 0; x < N; x++) {
        //             int tx = x, ty = y;
        //             get(tx, ty);
        //             //cout << get_value(x, y) << "(" << init(x, y) << ") ";
        //         }
        //         //cout << endl;
        //     }
        // }
        for(int y = D; y <= E; y++) {
            for(int x = F; x <= G; x++) {
                int tx = x, ty = y;
                get(tx, ty);
                //if(N < 10) printf("(%d, %d) -> (%d, %d)\n", x, y, tx, ty);
                h = (h * 31 + get_value(tx, ty, false)) % MOD;
            }
        }
        cout << h << endl;
    }
    return 0;
}

Measured memory_bytes: 2476