#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i, m, n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(x) begin(x), end(x)
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

constexpr ll inf = ll(1e18)+9;
vector<ll> dijkstra(vector<vector<pair<int, ll> > > const & g, int root) {
    int n = g.size();
    vector<ll> dist(n, inf);
    priority_queue<pair<ll, int> > que;
    dist[root] = 0;
    que.emplace(- dist[root], root);
    while (not que.empty()) {
        ll cost; int i; tie(cost, i) = que.top(); que.pop();
        if (dist[i] < - cost) continue;
        for (auto it : g[i]) {
            int j; ll delta; tie(j, delta) = it;
            if (- cost + delta < dist[j]) {
                dist[j] = - cost + delta;
                que.emplace(cost - delta, j);
            }
        }
    }
    return dist;
}

struct staff_t {
    int x, y;
    int repeat;
    string pattern;
};

const int dy[] = { -1, 1, 0, 0 };
const int dx[] = { 0, 0, 1, -1 };
bool is_on_field(int y, int x, int h, int w) { return 0 <= y and y < h and 0 <= x and x < w; }
int dir_from_cmd(char c) {
    switch (c) {
        case 'U': return 0;
        case 'D': return 1;
        case 'R': return 2;
        case 'L': return 3;
    }
    assert (false);
}

int main() {
    // input
    int w, h, n; cin >> w >> h >> n;
    int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
    vector<staff_t> staffs(n);
    repeat (i, n) {
        staff_t & staff = staffs[i];
        cin >> staff.x >> staff.y >> staff.repeat >> staff.pattern;
    }

    // solve
    // // staffs walk
    auto cnt_hr = vectors(h + 1, w, int());
    auto cnt_vr = vectors(h, w + 1, int());
    for (auto staff : staffs) {
        int x = staff.x;
        int y = staff.y;
        repeat (iteration, staff.repeat) {
            for (char c : staff.pattern) {
                int dir = dir_from_cmd(c);
                int nx = x + dx[dir];
                int ny = y + dy[dir];
                if (not is_on_field(ny, nx, h, w)) continue;
                switch (c) {
                    case 'U': cnt_hr[y    ][x] += 1; break;
                    case 'D': cnt_hr[y + 1][x] += 1; break;
                    case 'R': cnt_vr[y][x + 1] += 1; break;
                    case 'L': cnt_vr[y][x    ] += 1; break;
                }
                x = nx;
                y = ny;
            }
        }
    }
    // // deploy the cable
    auto at = [&](int y, int x) { return y * (w + 1) + x; };
    vector<vector<pair<int, ll> > > g((h + 1) * (w + 1));
    repeat (y, h + 1) {
        repeat (x, w + 1) {
            int z = at(y, x);
            if (y + 1 <= h) {
                int nz = at(y + 1, x);
                g[z].emplace_back(nz, cnt_vr[y][x]);
                g[nz].emplace_back(z, cnt_vr[y][x]);
            }
            if (x + 1 <= w) {
                int nz = at(y, x + 1);
                g[z].emplace_back(nz, cnt_hr[y][x]);
                g[nz].emplace_back(z, cnt_hr[y][x]);
            }
        }
    }
    ll result = dijkstra(g, at(sy, sx))[at(gy, gx)];

    // output
    printf("%lld\n", result);
    return 0;
}

Measured memory_bytes: 37140