import java.util.*;

public class teampractice_ls {
    final static long MOD = 1_000_000_007;

    static long[][] matmul(long[][] a, long[][] b) {
        int r = a.length;
        int p = b.length;
        int c = b[0].length;
        long[][] ans = new long[r][c];

        for (int i=0;i<r;++i) {
            for (int k=0;k<p;++k) {
                for (int j=0;j<c;++j) {
                    ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % MOD;
                }
            }
        }

        return ans;
    }

    static long[][] matexp(long[][] a, long pow) {
        int n = a.length;
        long[][] ans = new long[n][n];
        for (int i=0;i<n;++i) ans[i][i] = 1;

        while (pow > 0) {
            if ((pow&1) > 0) ans = matmul(ans, a);
            a = matmul(a, a);
            pow >>= 1;
        }

        return ans;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        long n = in.nextLong();
        int p = in.nextInt();
        int s = in.nextInt();
        int c = in.nextInt();


        long[][] left_trans = new long[s+1][s+1];
        for (int i=0;i<=s;++i) {
            if (i>0) left_trans[i-1][i] = i;
            left_trans[i][i] = 1;
            if (i+1<=s) left_trans[i+1][i] = s-i;
        }

        long[][] right_trans = new long[c+1][c+1];
        for (int j=0;j<=c;++j) {
            if (j>0) right_trans[j-1][j] = j;
            right_trans[j][j] = 1;
            if (j+1<=c) right_trans[j+1][j] = c-j;
        }

        long[][] state = new long[s+1][c+1];
        state[0][0] = 1;
    
        long curtime = 0;

        while (p-- >= 0) {
            long time;
            String side="";
            int sl=0, cl=0, tl=0;

            if (p<0) {
                time = n-1;
            } else {
                time = in.nextLong()-1;
                side = in.next();
                sl = in.nextInt();
                cl = in.nextInt();
                tl = in.nextInt();
            }

            state = matmul(matexp(left_trans, time-curtime), state);
            state = matmul(state, matexp(right_trans, time-curtime));
            curtime = time;

            if (p<0) break;

            if (side.equals("B")) {
                for (int i=0;i<=s;++i) {
                    for (int j=0;j<=c;++j) {
                        if (i<sl || j <cl || i+j<tl) state[i][j] = 0;
                    }
                }
            } else {
                for (int i=0;i<=s;++i) {
                    for (int j=0;j<=c;++j) {
                        if (s-i<sl || c-j<cl || s-i+c-j<tl) state[i][j] = 0;
                    }
                }
            }
        }

        System.out.println(state[0][0]);
    }
}