#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#define MAXN 255
using namespace std;
struct coord
{
int x, y;
coord(int x=0, int y=0) : x(x), y(y) {}
};
struct gheiz
{
int t, d;
gheiz(int t, int d) : t(t), d(d) {}
};
vector<gheiz> a[MAXN][MAXN];
coord st, fin;
int best[MAXN][MAXN], n, m, p;
int dx[3] = {-1, 0, 1};
int dy[3] = {0, 1, 0};
void citire()
{
scanf("%d %d %d", &n, &m, &p);
scanf("%d %d", &st.x, &fin.x);
st.y = 1; fin.y = m;
int x, y, r, t, d;
for (int k = 1; k <= p; k++)
{
scanf("%d %d %d %d %d", &x, &y, &r, &t, &d);
gheiz g(t, d);
for (int i = max(1, x-r); i <= min(n, x+r); i++)
for (int j = max(1, y-r); j <= min(m, y+r); j++)
a[i][j].push_back(g);
}
}
int check(coord nou, int time)
{
for (int i = 0; i < a[nou.x][nou.y].size(); i++)
{
gheiz g = a[nou.x][nou.y][i];
if (!(time%(g.d+g.t) < g.t))
return 0;
}
return 1;
}
queue<coord> q;
void solve()
{
q.push(st);
best[st.x][st.y] = 1;
while (!q.empty())
{
coord top = q.front(), nou;
q.pop();
for (int i = 0; i < 3; i++)
{
nou = coord(top.x+dx[i], top.y+dy[i]);
if (nou.x < 1 || nou.x > n || nou.y < 1 || nou.y > m || best[nou.x][nou.y])
continue;
if (check(nou, best[top.x][top.y]))
{
best[nou.x][nou.y] = best[top.x][top.y]+1;
q.push(nou);
if (nou.x == fin.x && nou.y == fin.y)
return;
}
}
best[top.x][top.y] = 0;
}
}
int main()
{
freopen("gheizere.in", "r", stdin);
freopen("gheizere.out", "w", stdout);
citire();
solve();
printf("%d", best[fin.x][fin.y]);
return 0;
}