#include<iostream>
#include<map>
#include<vector>
#include<cstring>
#include<queue>
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;

map<char, int> dx, dy;
int idx[4] = {1, 0, -1, 0};
int idy[4] = {0, -1, 0, 1};

int main(int argc, char *argv[]){
  dx['U'] = 0,  dy['U'] = -1;
  dx['D'] = 0,  dy['D'] = 1;
  dx['R'] = 1,  dy['R'] = 0;
  dx['L'] = -1,  dy['L'] = 0;

  int w, h, n, csx, csy, ctx, cty;
  cin >> w >> h >> n;
  cin >> csx >> csy >> ctx >> cty;
  int grid[2*h + 5][2*w + 5];
  int dp[h + 1][w + 1];
  memset(grid, 0, sizeof(grid));

  for (int i = 0; i <= h; i++) {
    for (int j = 0; j <= w; j++) {
      dp[i][j] = 1e9;
    }
  }
  
  int nx, ny , count;
  string dist;
  for (int i = 0; i < n; i++) {
    cin >> nx >> ny >> count >> dist;
    for (int j = 0; j < dist.length()*count; j++) {
      char d = dist[j%dist.length()];
      if(0 <= ny + dy[d] && ny + dy[d] < h &&
         0 <= nx + dx[d] && nx + dx[d] < w){
        grid[2*ny + dy[d] + 1][2*nx + dx[d] + 1]++;
        ny += dy[d], nx += dx[d];
      }
    }
  }
  dp[csy][csx] = 0;
  priority_queue<piii ,vector<piii>, greater<piii> > que;
  que.push(mp(0, mp(csx, csy)));
  while(!que.empty()){
    piii v = que.top();que.pop();
    int x, y, c;
    c = v.first;
    x = v.second.first;
    y = v.second.second;
    for (int i = 0; i < 4; i++) {
      int nx = x + idx[i], ny = y + idy[i];
      if(0 <= nx && nx <= w &&
         0 <= ny && ny <= h &&
         dp[ny][nx] > c + grid[2*y + idy[i]][2*x + idx[i]]){
        dp[ny][nx] = c + grid[2*y + idy[i]][2*x + idx[i]];
        que.push(mp(dp[ny][nx], mp(nx, ny)));
      }
    }
  }

  // std::cout << "grid:" << std::endl;
  // for (int i = 0; i <= 2*h; i++) {
  //   for (int j = 0; j <= 2*w; j++) {
  //     std::cout << grid[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  // std::cout << "dp:" << std::endl;
  // for (int i = 0; i <= h; i++) {
  //   for (int j = 0; j <= w; j++) {
  //     std::cout << dp[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  
  std::cout << dp[cty][ctx] << std::endl;
  return 0;
}