#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MN = 40400;
const ll MD = 1e9+7;

int N;
int A, B, C;
int rowmp[MN]; //y = rowmp[y]
int colmp[MN];
int dir, rev;

int xc(int x, int y) {
    switch (rev*4+dir) {
    case 0:
    case 6:
        return x;
    case 1:
    case 5:
        return y;
    case 2:
    case 4:
        return N-1-x;
    case 3:
    case 7: 
        return N-1-y;
    }
    assert(false);
}

int yc(int x, int y) {
    switch(rev*4+dir) {
    case 0:
    case 4:
        return y;
    case 3:
    case 5:
        return x;
    case 2:
    case 6:
        return N-1-y;
    case 1:
    case 7:
        return N-1-x;
    }
    assert(false);
}


map<P, int> mp;

int get(int x, int y) {
    int xx = xc(x, y);
    int yy = yc(x, y);
    xx = colmp[xx];
    yy = rowmp[yy];
    if (mp.count(P(xx, yy))) {
        return mp[P(xx, yy)];
    }
    return ((ll)A*(yy+1)+(ll)B*(xx+1)) % C;
}

void set(int x, int y, int d) {
    int xx = xc(x, y);
    int yy = yc(x, y);
    xx = colmp[xx];
    yy = rowmp[yy];
    mp[P(xx, yy)] = d;
}

int main() {
    int Q, D, E, F, G;
    cin >> N >> Q >> A >> B >> C >> D >> E >> F >> G;
    D--; F--;
    for (int i = 0; i < N; i++) {
        rowmp[i] = colmp[i] = i;
    }
    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < N; j++) {
    //         printf("%d ", get(j, i));
    //     } printf("\n");
    // }
    for (int i = 0; i < Q; i++) {
        string s;
        cin >> s;
        if (s == "WR") {
            int y, x, d;
            cin >> y >> x >> d; y--; x--;
            set(x, y, d);
        } else if (s == "CP") {
            int y1, x1, y2, x2;
            cin >> y1 >> x1 >> y2 >> x2;
            y1--; x1--; y2--; x2--;
            set(x2, y2, get(x1, y1));
        } else if (s == "SR") {
            int y1, y2;
            cin >> y1 >> y2; y1--; y2--;
            if (dir % 2 == 0) {
                y1 = yc(-1, y1);
                y2 = yc(-1, y2);
                swap(rowmp[y1], rowmp[y2]);
            } else {
                y1 = xc(-1, y1);
                y2 = xc(-1, y2);
                swap(colmp[y1], colmp[y2]);
            }
        } else if (s == "SC") {
            int x1, x2;
            cin >> x1 >> x2; x1--; x2--;
            if (dir % 2 == 0) {
                x1 = xc(x1, -1);
                x2 = xc(x2, -1);
                swap(colmp[x1], colmp[x2]);
            } else {
                x1 = yc(x1, -1);
                x2 = yc(x2, -1);
                swap(rowmp[x1], rowmp[x2]);
            }
        } else if (s == "RL") {
            if (!rev) {
                dir = (dir+3) % 4;
            } else {
                dir = (dir+1) % 4;
            }
        } else if (s == "RR") {
            if (!rev) {
                dir = (dir+1) % 4;
            } else {
                dir = (dir+3) % 4;
            }
        } else if (s == "RH") {
            rev = 1-rev;
            dir += 2;
            dir %= 4;
        } else if (s == "RV") {
            rev = 1-rev;
        }
//        printf("dir %d rev %d\n", dir, rev);
        // for (int i = 0; i < N; i++) {
        //     for (int j = 0; j < N; j++) {
        //         printf("%d ", get(j, i));
        //     } printf("\n");
        // }
    }
    ll h = 314159265;
    for (int i = D; i < E; i++) {
        for (int j = F; j < G; j++) {
            h = (31 * h + get(j, i)) % MD;
        }
    }
    cout << h << endl;
    return 0;
}

Measured memory_bytes: 2160