#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int w,h,n;
int sy,sx,gy,gx;
int y,x,t,prvx,prvy;
string s;
int d[1010][510];
ll dist[500000];
vector<P> g[500000];
const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
const char dir[] = {'U', 'R', 'D', 'L'};

int main(){
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  cin >> w >> h >> n;
  cin >> sx >> sy >> gx >> gy;
  memset(d,0,sizeof(d));

  for(int i=0;i<n;i++){
    cin >> x >> y >> t >> s;
    for(int j=0;j<t;j++){
      for(int k=0;k<(int)s.size();k++){
	if(s[k] == 'U'){
	  prvx = x; prvy = y;
	  if(0<=y+dy[0] && y+dy[0]<h)y += dy[0];
	  if(0<=x+dx[0] && x+dx[0]<w)x += dx[0];
	  if(prvx == x && prvy == y)continue;
	  d[2*(y+1)][x]++;
	}else if(s[k] == 'R'){
	  prvx = x; prvy = y;
	  if(0<=y+dy[1] && y+dy[1]<h)y += dy[1];
	  if(0<=x+dx[1] && x+dx[1]<w)x += dx[1];
	  if(prvx == x && prvy == y)continue;
	  d[2*y+1][x]++;
	}else if(s[k] == 'D'){
	  prvx = x; prvy = y;
	  if(0<=y+dy[2] && y+dy[2]<h)y += dy[2];
	  if(0<=x+dx[2] && x+dx[2]<w)x += dx[2];
	  if(prvx == x && prvy == y)continue;
	  d[2*y][x]++;
	}else if(s[k] == 'L'){
	  prvx = x; prvy = y;
	  if(0<=y+dy[3] && y+dy[3]<h)y += dy[3];
	  if(0<=x+dx[3] && x+dx[3]<w)x += dx[3];
	  if(prvx == x && prvy == y)continue;
	  d[2*y+1][x+1]++;
	}
      }
    }
  }
  /*
  for(int i=0;i<2*h+1;i++){
    if(i&1){
      for(int j=0;j<w+1;j++)cout << d[i][j] << " ";
    }else{
      for(int j=0;j<w;j++)cout << d[i][j] << " ";
    }
    cout << endl;
  }
  */
  for(int i=0;i<h+1;i++){
    for(int j=0;j<w;j++){
      int f = i*(w+1)+j, t = i*(w+1)+j+1;
      g[f].push_back(P(d[2*i][j],t));
      g[t].push_back(P(d[2*i][j],f));
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w+1;j++){
      int f = i*(w+1)+j, t = (i+1)*(w+1)+j;
      g[f].push_back(P(d[2*i+1][j],t));
      g[t].push_back(P(d[2*i+1][j],f));
    }
  }

  priority_queue<P,vector<P>,greater<P> > q;
  q.push(P(0,sy*(w+1)+sx));
  for(int i=0;i<(w+1)*(h+1);i++)dist[i] = 1e15;
  dist[sy*(w+1)+sx] = 0;

  while(q.size()){
    P p = q.top(); q.pop();
    int v = p.second;
    ll cost = p.first;

    if(v==gy*(w+1)+gx){
      break;
    }
    if(dist[v] < cost)continue;

    for(int i=0;i<g[v].size();i++){
      int nxt = g[v][i].second;
      ll ncost = cost + g[v][i].first;
      if(dist[nxt] > ncost){
	dist[nxt] = ncost;
	q.push(P(ncost,nxt));
      }
    }
  }
  cout << dist[gy*(w+1)+gx] << endl;
}