#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define TASKNAME "fatalism"

const int MaxN = 100, MaxK = 100, MaxD = 4;
const int dx [MaxD] = {-1,  0,  1,  0},
          dy [MaxD] = { 0, -1,  0,  1};
const char code [MaxD] = {'L', 'U', 'R', 'D'};

bool a [MaxN + 2] [MaxN + 2];
int x [MaxK], y [MaxK], d [MaxK];
bool b [MaxK], q [MaxK];

int main (void)
{
 int i, j, k, m, n, t, u, v;
 char c;
 freopen (TASKNAME ".in", "r", stdin);
 freopen (TASKNAME ".out", "w", stdout);
 while (scanf (" %d %d %d", &m, &n, &k) != EOF)
 {
  assert (1 <= m && m <= MaxN);
  assert (1 <= n && n <= MaxN);
  assert (1 <= k && k <= MaxK);
  memset (a, 1, sizeof (a));
  for (i = 1; i <= n; i++)
   for (j = 1; j <= m; j++)
   {
    assert (scanf (" %c", &c) == 1);
    assert (c == 'X' || c == '.');
    a[j][i] = (c == 'X');
   }
  memset (b, 1, sizeof (b));
  for (i = 0; i < k; i++)
  {
   assert (scanf (" %d %d %c", &u, &v, &c) == 3);
   assert (1 <= u && u <= m);
   assert (1 <= v && v <= n);
   x[i] = u;
   y[i] = v;
   for (j = 0; j < MaxD; j++)
    if (c == code[j])
     break;
   assert (j < MaxD);
   d[i] = j;
  }
  for (t = 0; ; t++)
  {
   for (i = 0; i < k; i++) if (b[i])
    if (a[x[i]][y[i]])
     b[i] = false;
   for (i = 0; i < k; i++) if (b[i])
    for (j = i + 1; j < k; j++) if (b[j])
     if (x[i] == x[j] && y[i] == y[j])
      b[i] = b[j] = false; // works for >2 robots, too
   memset (q, 0, sizeof (q));
   for (i = 0; i < k; i++) if (b[i])
   {
    u = x[i]; v = y[i];
    while (1)
    {
     u += dx[d[i]];
     v += dy[d[i]];
     if (a[u][v]) break;
     for (j = 0; j < k; j++) if (b[j])
      if (x[j] == u && y[j] == v)
       q[j] = true;
    }
   }
   for (i = 0; i < k; i++)
    if (q[i])
     b[i] = false;
   if (t == 0)
    for (i = 0; i < k; i++) if (!b[i])
     assert (false);
   for (i = 0; i < k; i++) if (b[i])
    break;
   if (i == k) break;
   for (i = 0; i < k; i++) if (b[i])
    x[i] += dx[d[i]],
    y[i] += dy[d[i]];
  }
  printf ("%d\n", t);
 }
 return 0;
}
