#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

const ll MOD = 1e9 + 7;
int state;
int n, q;
int row[40010];
int column[40010];
int A, B, C, D, E, F, G;
char str[100];
map<pair<int, int>, int> vs;

void GetPos(int &x, int &y) {
  int rotate = state & 3;
  REP(i, rotate) {
    int py = y;
    y = n - x - 1;
    x = py;
  }
  if (state & 4) {
    y = n - y - 1;
  }
}
void GetTruePos(int &x, int &y) {
  GetPos(x, y);
  x = column[x]; y = row[y];
}
void SwapPos(int c1, int r1, int c2, int r2) {
  GetPos(c1, r1); GetPos(c2, r2);
  if (c1 == c2) {
    swap(row[r1], row[r2]);
  } else {
    assert(r1 == r2);
    swap(column[c1], column[c2]);
  }
}
ll GetValue(int x, int y) {
  GetTruePos(x, y);
  ll v = ((ll)(y + 1) * A + (ll)(x + 1) * B) % C;
  if (vs.count(make_pair(x, y))) { v = vs[make_pair(x, y)]; }
  return v;
}

void PrintMatrix() {
  REP(y, n) {
    REP(x, n) {
      printf("%lld ", GetValue(x, y));
    }
    puts("");
  }
  puts("");
}

int main() {
  while (scanf("%d %d  %d %d %d  %d %d %d %d", &n, &q, &A, &B, &C, &D, &E, &F, &G) > 0) {
    D--; E--; F--; G--;
    MEMSET(row, 0x0f); MEMSET(column, 0x0f);
    REP(i, n) { row[i] = i; column[i] = i; }
    state = 0;
    vs.clear();
    //PrintMatrix();
    REP(i, q) {
      scanf("%s", str);
      if (str[0] == 'W') {
        int r, c, v;
        scanf("%d %d %d", &r, &c, &v);
        r--; c--;
        GetTruePos(c, r);
        vs[make_pair(c, r)] = v;
      } else if (str[0] == 'C') {
        int r1, c1, r2, c2;
        scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
        r1--; c1--; r2--; c2--;
        GetTruePos(c2, r2);
        vs[make_pair(c2, r2)] = GetValue(c1, r1);
      } else if (str[0] == 'S' && str[1] == 'R') {
        int r1, r2;
        scanf("%d %d", &r1, &r2);
        r1--; r2--;
        SwapPos(0, r1, 0, r2);
      } else if (str[0] == 'S' && str[1] == 'C') {
        int c1, c2;
        scanf("%d %d", &c1, &c2);
        c1--; c2--;
        SwapPos(c1, 0, c2, 0);
      } else if (str[1] == 'L') {
        int conv[8] = { 3, 0, 1, 2, 7, 4, 5, 6 };
        state = conv[state];
      } else if (str[1] == 'R') {
        int conv[8] = { 1, 2, 3, 0, 5, 6, 7, 4 };
        state = conv[state];
      } else if (str[1] == 'H') {
        int conv[8] = { 4, 7, 6, 5, 0, 3, 2, 1 };
        state = conv[state];
      } else if (str[1] == 'V') {
        int conv[8] = { 6, 5, 4, 7, 2, 1, 0, 3 };
        state = conv[state];
      }
      //PrintMatrix();
    }
    ll ans = 314159265;
    FOREQ(y, D, E) {
      FOREQ(x, F, G) {
        ans = (ans * 31 + GetValue(x, y)) % MOD;
      }
    }
    printf("%lld\n", ans);
  }
}