#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;
typedef pair<int,int> pii;
typedef long long ll;

int ROW[40001];
int COL[40001];
int N,Q,A,B,C,D,E,F,G;

/*
  state
  
  AB
  CD

  BD
  AC

  DC
  BA

  CA
  DB

  BA
  DC

  AC
  BD

  CD
  AB

  DB
  CA
 */
pii func(int state, int r, int c) {
  pii res;
  if (state == 0) res = pii(r,c);
  else if (state == 3) res = pii(N-1-c,r);
  else if (state == 2) res = pii(N-1-r,N-1-c);
  else if (state == 1) res = pii(c, N-1-r);
  else if (state == 4) res = pii(r,N-1-c);
  else if (state == 5) res = pii(c, r);
  else if (state == 6) res = pii(N-1-r,c);
  else if (state == 7) res = pii(N-1-c,N-1-r);
  return pii(ROW[res.first], COL[res.second]);
}
pii func2(int state, int r, int c) {
  pii res;
  if (state == 0) res = pii(r,c);
  else if (state == 3) res = pii(N-1-c,r);
  else if (state == 2) res = pii(N-1-r,N-1-c);
  else if (state == 1) res = pii(c, N-1-r);
  else if (state == 4) res = pii(r,N-1-c);
  else if (state == 5) res = pii(c, r);
  else if (state == 6) res = pii(N-1-r,c);
  else if (state == 7) res = pii(N-1-c,N-1-r);
  return pii(res.first, res.second);
}
map<pii, int> mp;

int get(int state, int r, int c) {
  pii p = func(state, r, c);
  //cout << r << " " << c << " : " << p.first << "," << p.second << " " << mp.count(pii(p)) << endl;
  if (mp.count(pii(p))) return mp[pii(p)];
  else return ((p.first+1LL)*A + (p.second+1LL)*B) % C;
}

int main() {
  int rh[8] = {6,5,4,7,2,1,0,3};
  int rv[8] = {4,7,6,5,0,3,2,1};
  int NUM = 0;
  while(cin>>N>>Q>>A>>B>>C>>D>>E>>F>>G) {
    if (NUM++) return 0;
    mp.clear();
    REP(i,N) ROW[i] = COL[i] = i;
    int state = 0;
    
    REP(i,Q+1) {
      // cout << state << endl;
      // REP(j, N) {
      //   REP(k,N) cout << get(state,j,k) << " ";
      //   cout << endl;
      // }cout << endl;
      if (i==Q) break;
      string op;
      cin >> op;
      // cout << op << endl;
      if (op == "WR") {
        int r,c,v;cin>>r>>c>>v;r--;c--;
        //cout << func(state, r, c).first << " "<<func(state, r,c).second << endl;
        mp[func(state, r, c)] = v;
      } else if (op == "CP") {
        int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;r1--;c1--;r2--;c2--;
        pii p2 = func(state, r2, c2);
        mp[p2] = get(state, r1, c1);
      } else if (op == "SR") {
        int r1, r2; cin >> r1 >> r2; r1--;r2--;
        pii p1 = func2(state, r1, 0), p2 = func2(state, r2, 0);
        if (state % 2)
          swap(COL[p1.second], COL[p2.second]);
        else
          swap(ROW[p1.first], ROW[p2.first]);
      } else if (op == "SC") {
        int c1, c2; cin >> c1 >> c2; c1--; c2--;
        pii p1 = func2(state, 0, c1), p2 = func2(state, 0, c2);
        if (state % 2)
          swap(ROW[p1.first], ROW[p2.first]);
        else
          swap(COL[p1.second], COL[p2.second]);
      } else if (op == "RL") {
        state = (state + 1) % 4 + state/4*4;
      } else if (op == "RR") {
        state = (state + 3) % 4 + state/4*4;
      } else if (op == "RH") {
        state = rh[state];
      } else {
        state = rv[state];
      }
    }
    ll h = 314159265;
    for (int i=D-1; i<E; ++i) {
      for (int j=F-1; j<G; ++j) {
        int b = get(state, i, j);
        //if (b < 0) cout << b << endl;
        h = (31*h+b) % 1000000007;
        //cout << h << endl;
      }
    }
    cout << h << endl; 
  }
}

Measured memory_bytes: 1524