//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1e8;

struct Edge{
  int to, cost;

  Edge(int t, int c): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
};
typedef vector< vector<Edge> > Graph;

int W, H, N;
int idx(int x, int y){
  return y*(W+1)+x;
}
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

void Dijkstra(const Graph& edges, vector<int>& d, int s){
  const int V = edges.size();
  priority_queue<PII, vector<PII>, greater<PII> > pq;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  pq.push(MP(0,s));

  while(!pq.empty()){
	PII pii = pq.top(); pq.pop();
	int v = pii.second;
	if(d[v] < pii.first) continue;
	for(int i=0;i<edges[v].size();++i){
	  const Edge& e = edges[v][i];
	  if(d[e.to] > d[v] + e.cost){
		d[e.to] = d[v] + e.cost;
		pq.push(MP(d[e.to], e.to));
	  }
	}
  }
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> W >> H >> N;
  int sx, sy, ex, ey; cin >> sx >> sy >> ex >> ey;
  Graph G((H+1)*(W+1));
  for(int y=0;y<=H;++y){
	for(int x=0;x<=W;++x){
	  REP(i,4){
		int tx = x + dx[i], ty = y + dy[i];
		if(tx < 0 || W+1 <= tx || ty < 0 || H+1 <=ty) continue;
		G[idx(x,y)].PB(Edge(idx(tx,ty), 0));
	  }
	}
  }
  
  REP(i,N){
	int px, py, T; cin >> px >> py >> T;
	string s; cin >> s;
	REP(t,T){
	  REP(j,SZ(s)){
		int d;
		switch(s[j]){
		case 'R':
		  d = 0;
		  break;
		case 'D':
		  d = 1;
		  break;
		case 'L':
		  d = 2;
		  break;
		case 'U':
		  d = 3;
		  break;
		}
		int tx = px + dx[d], ty = py + dy[d];		
		if(tx < 0 || W <= tx || ty < 0 || H <= ty) continue;
		int pid, tid;
		if(d%2)
		  pid = idx(tx, max(py,ty)), tid = idx(tx+1, max(py,ty));
		else
		  pid = idx(max(px,tx), ty), tid = idx(max(px,tx), ty+1);

		int k;
		for(k=0;;++k) if(G[pid][k].to == tid) break;
		G[pid][k].cost++;
		for(k=0;;++k) if(G[tid][k].to == pid) break;
		G[tid][k].cost++;
		px = tx, py = ty;
	  }
	}
  }

  VI res((H+1)*(W+1));
  Dijkstra(G, res, idx(sx,sy));
  cout << res[idx(ex,ey)] << endl;
  
  return 0;
}

Measured memory_bytes: 21768