(defparameter n (read))
(defparameter q (read))
(defparameter address (read-line))
(defparameter magic-words
  (loop repeat q
        collect (list (character (read)) (character (read)))))

(defparameter golem-vector
  (make-array n :initial-element 1))

(defun char-positions (char string)
  (declare (optimize (speed 3) (debug 0) (safety 0)))
  (let ((n (length string)))
    (labels ((rec (index acc)
               (cond ((< index 0) acc)
                     ((char= char (char string index))
                      (rec (1- index) (cons index acc)))
                     (t (rec (1- index) acc)))))
      (rec (1- n) nil))))

(defun f (size golem-vector address magic-words)
  (loop for magic-word in magic-words
        do (destructuring-bind (ti di) magic-word
             (let ((positions (char-positions ti address)))
               (mapc (lambda (pos)
                       (let ((cur-pos-golems (svref golem-vector pos))
                             (r-pos (1- pos))
                             (l-pos (1+ pos)))
                         (cond ((and (char= di #\R)
                                     (<= 0 r-pos (1- size)))
                                (incf (svref golem-vector r-pos)
                                      cur-pos-golems))
                               ((and (char= di #\L)
                                     (<= 0 l-pos (1- size)))
                                (incf (svref golem-vector l-pos)
                                      cur-pos-golems)))
                         (setf (svref golem-vector pos) 0)))
                     positions))))
  golem-vector)

(defun vector-sum (vector)
  (let ((n (length vector)))
    (labels ((rec (i acc)
               (if (zerop i)
                   acc
                   (rec (1- i) (+ (svref vector (1- i)) acc)))))
      (rec n 0))))

(princ (vector-sum (f n golem-vector address magic-words)))
