#include <bits/stdc++.h>
using namespace std;
namespace zyt {
template <typename T>
inline bool read(T &x) {
  char c;
  bool f = false;
  x = 0;
  do c = getchar();
  while (c != EOF && c != '-' && !isdigit(c));
  if (c == EOF) return false;
  if (c == '-') f = true, c = getchar();
  do x = x * 10 + c - '0', c = getchar();
  while (isdigit(c));
  if (f) x = -x;
  return true;
}
template <typename T>
inline void write(T x) {
  static char buf[20];
  char *pos = buf;
  if (x < 0) putchar('-'), x = -x;
  do *pos++ = x % 10 + '0';
  while (x /= 10);
  while (pos > buf) putchar(*--pos);
}
const int N = 510, K = 5e5 + 10, INF = 0x3f3f3f3f;
const int UP = 0, LEFT = 1;
const int dx[] = {0, 1, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m, k, pcnt;
long long dp[2][N][N][2];
struct node {
  int y, dis, dir, e;
  bool operator<(const node &b) const { return y < b.y; }
};
vector<node> pt[N];
void getmin(long long &a, const long long b) { a = min(a, b); }
int work() {
  read(n), read(m), read(k);
  while (k--) {
    int x, y, d, t, e;
    read(x), read(y), read(d), read(t), read(e);
    bool flag[2];
    flag[0] = flag[1] = false;
    for (int i = 0; i < 4; i++) {
      int xx = x + d * dx[i], yy = y + d * dy[i];
      if (xx + yy >= t && (xx + yy) % 4 == (t + i) % 4) {
        if (i < 2)
          pt[xx].push_back((node){yy, -1, 0, e}), flag[i] = true;
        else if (i == 2) {
          if (flag[0])
            pt[xx].push_back((node){yy, d, UP, e});
          else if (flag[1])
            pt[xx].push_back((node){yy, d, LEFT, e});
          else
            pt[xx].push_back((node){yy, -1, 0, e});
        } else if (i == 3) {
          if (flag[0])
            pt[xx].push_back((node){yy, d, LEFT, e});
          else
            pt[xx].push_back((node){yy, -1, 0, e});
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int now = i & 1;
    memset(dp[now], INF, sizeof(dp[now]));
    sort(pt[i].begin(), pt[i].end());
    vector<node>::iterator it = pt[i].begin();
    for (int j = 0; j < m; j++) {
      static long long tmp1[N], tmp2[N];
      long long sum = 0;
      memset(tmp1, 0, sizeof(long long[i + 1]));
      memset(tmp2, 0, sizeof(long long[j + 1]));
      while (it != pt[i].end() && it->y == j) {
        sum += it->e;
        for (int k = 1; k <= i; k++)
          if (it->dis == -1 || !(it->dir == UP && it->dis <= k))
            tmp1[k] += it->e;
        for (int k = 1; k <= j; k++)
          if (it->dis == -1 || !(it->dir == LEFT && it->dis <= k))
            tmp2[k] += it->e;
        it++;
      }
      if (!i && !j) dp[now][j][0][LEFT] = dp[now][j][0][UP] = sum;
      for (int k = 1; k <= i; k++)
        getmin(dp[now][j][k][UP], dp[now ^ 1][j][k - 1][UP] + tmp1[k]);
      for (int k = 1; k <= j; k++)
        getmin(dp[now][j][k][LEFT], dp[now][j - 1][k - 1][LEFT] + tmp2[k]);
      for (int k = 1; k <= i; k++)
        getmin(dp[now][j][0][LEFT], dp[now][j][k][UP]);
      for (int k = 1; k <= j; k++)
        getmin(dp[now][j][0][UP], dp[now][j][k][LEFT]);
    }
  }
  write(min(dp[(n - 1) & 1][m - 1][0][UP], dp[(n - 1) & 1][m - 1][0][LEFT]));
  return 0;
}
}  // namespace zyt
int main() { return zyt::work(); }
