/*
   All this dirty code written by avm.
*/
import java.util.*;
import java.io.*;
public class fatalism_am
  {
  static final String filename = "fatalism";
  static final boolean DEBUG_OUTPUT = false;
  static BufferedReader in;
  static PrintStream out;
  static int w,h,nr;
  static final int DX[] = {0,-1,1,0};
  static final int DY[] = {-1,0,0,1};
  static final String Dir = "ULRD";
  static boolean empty[][];
  static Robot[] r;
  static void print(int t)
    {
    if (!DEBUG_OUTPUT) return;
    out.println("========= t = " + Integer.toString(t) + " =========");
    char c[][] = new char[h][w];
    int i,j,k;
    for(j=0;j<h;j++)
      for(i=0;i<w;i++)
        c[j][i] = empty[j][i] ? '.' : 'X';
    for(k=0;k<nr;k++) if (!r[k].died)
      c[r[k].y][r[k].x] = Dir.charAt(r[k].dir);
    for(j=0;j<h;j++)
      {
      for(i=0;i<w;i++)
        out.print(c[j][i]);
      out.println();
      }
    }

  static boolean isEmpty(int y,int x)
    {
    if (x < 0 || x >= w || y < 0 || y >= h) return false;
    return empty[y][x];
    }
  static class Robot
    {
    int x,y,dir;
    boolean died;
    Robot(String s)
      {
      StringTokenizer st = new StringTokenizer(s);
      x = Integer.parseInt(st.nextToken()) - 1;
      y = Integer.parseInt(st.nextToken()) - 1;
      assert(x >= 0 && x < w);
      assert(y >= 0 && y < h);
      s = st.nextToken();
      assert(s.length() == 1);
      dir = Dir.indexOf(s);
      if (DEBUG_OUTPUT)
        {
        out.print("Read robot(" + Integer.toString(x) + "," + Integer.toString(y) + ") dir = " + Integer.toString(dir));
        out.print(" DX = " + Integer.toString(DX[dir]));
        out.println(" DY = " + Integer.toString(DY[dir]));      
        }
      died = false;
      }
    void pcell(int y,int x)
      {
      out.print("(" + Integer.toString(x) + "," + Integer.toString(y) + ")");
      }

    void move()
      {
      /*
      if (DEBUG_OUTPUT)
        {
        out.print("move robot from ");
        pcell(y,x);
        }
      */
      x += DX[dir];
      y += DY[dir];
      /*
      if (DEBUG_OUTPUT)
        {
        out.print(" to ");
        pcell(y,x);
        out.println();
        }
      */
      died = died || !isEmpty(y,x);
      }
    }
  static void removeDiedRobots()
    {
    int i,m = -1;
    for(i=0;i<nr;i++) if (!r[i].died) r[++m] = r[i];
    nr = m+1;
    }
  static void killByCollision()
    {
    int i,j;
    for(i=0;i<nr;i++)
      for(j=i+1;j<nr;j++)
        if (r[i].x == r[j].x && r[i].y == r[j].y)
          {
          r[i].died = true;
          r[j].died = true;
          }
    removeDiedRobots();
    }
  static void killByLaser()
    {
    int i;
    boolean a[][] = new boolean[h][w];
    for(i=0;i<nr;i++)
      {
      int X = r[i].x,Y = r[i].y;
      X += DX[r[i].dir];
      Y += DY[r[i].dir];
      while(isEmpty(Y,X))
        {
        a[Y][X] = true;
        X += DX[r[i].dir];
        Y += DY[r[i].dir];
        }
      }
    for(i=0;i<nr;i++) 
      if (a[r[i].y][r[i].x])
        r[i].died = true;
    removeDiedRobots();
    }

  static void test() throws IOException
    {
    int i,j,k;
    String s;
    StringTokenizer st = new StringTokenizer(in.readLine());
    w = Integer.parseInt(st.nextToken());
    h = Integer.parseInt(st.nextToken());
    nr = Integer.parseInt(st.nextToken());
    assert(w >= 1 && w <= 100);
    assert(h >= 1 && h <= 100);
    assert(nr >= 0 && nr <= 100);
    assert(!st.hasMoreTokens());
    empty = new boolean[h][w];
    for(j=0;j<h;j++)
      {
      s = in.readLine();
      assert(s.length() == w);
      for(i=0;i<w;i++)
        {
        char c = s.charAt(i);
        assert(c == '.' || c == 'X');
        empty[j][i] = (c == '.');
        }
      }
    if (nr == 0)
      {
      out.println(0);
      return;
      }

    r = new Robot[nr];
    for(i=0;i<nr;i++)
      r[i] = new Robot(in.readLine());
    k = nr;
    killByCollision();assert(k == nr);
    killByLaser();assert(k == nr);
    
    for(int t=1;;t++)
      {
      print(t-1);
      for(i=0;i<nr;i++) r[i].move();
      removeDiedRobots();
      killByCollision();
      killByLaser();
      if (nr == 0)
        {
        out.println(t);
        break;
        }
      }
    }
  public static void main (String[] argv) throws IOException
    {
    in = new BufferedReader(new InputStreamReader(new FileInputStream(filename+ ".in")));
    out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename + ".out"))); 
    test();
    in.close();
    out.close();
    }
  }

