#include <bits/stdc++.h>
using namespace std;
const int max_n = 505;
const long long inf = 1000111222000111222LL;
const int max_k = 500555;
int n, m, k, cost[max_k];
long long dp[max_n][max_n], s1[max_n][max_n], s2[max_n][max_n];
vector<pair<int, int>> all1[max_n][max_n], all2[max_n][max_n];
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; ++i) {
    int x, y, d, t;
    scanf("%d%d%d%d%d", &x, &y, &d, &t, &cost[i]);
    const int sdx[] = {0, d, d, 0};
    const int sdy[] = {0, -d, 0, d};
    vector<pair<int, int>> v;
    for (int j = 0; j < 4; ++j) {
      int nx = x + sdx[j], ny = y + sdy[j];
      if ((t + j) % 4 == (nx + ny) % 4 && t <= nx + ny) {
        v.push_back({nx, ny});
      }
    }
    sort(v.begin(), v.end());
    if (v.size() == 1) {
      s1[v[0].first][v[0].second] += cost[i];
      s2[v[0].first][v[0].second] += cost[i];
    } else if (v.size() == 2) {
      if (v[0].first == v[1].first) {
        s1[v[0].first][v[0].second] += cost[i];
        all1[v[1].first][v[1].second].push_back({v[0].second, cost[i]});
        s2[v[0].first][v[0].second] += cost[i];
        s2[v[1].first][v[1].second] += cost[i];
      } else if (v[0].second == v[1].second) {
        s2[v[0].first][v[0].second] += cost[i];
        all2[v[1].first][v[1].second].push_back({v[0].first, cost[i]});
        s1[v[0].first][v[0].second] += cost[i];
        s1[v[1].first][v[1].second] += cost[i];
      } else {
        s1[v[0].first][v[0].second] += cost[i];
        s2[v[0].first][v[0].second] += cost[i];
        s1[v[1].first][v[1].second] += cost[i];
        s2[v[1].first][v[1].second] += cost[i];
      }
    } else if (v.size() > 2) {
      exit(228);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      dp[i][j] = inf;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      long long add = 0;
      for (int to = j + 1; to < m; ++to) {
        add += s1[i][to];
        for (const auto &p : all1[i][to]) {
          if (p.first < j) {
            add += p.second;
          }
        }
        dp[i][to] = min(dp[i][to], dp[i][j] + add);
      }
      add = 0;
      for (int to = i + 1; to < n; ++to) {
        add += s2[to][j];
        for (const auto &p : all2[to][j]) {
          if (p.first < i) {
            add += p.second;
          }
        }
        dp[to][j] = min(dp[to][j], dp[i][j] + add);
      }
    }
  }
  cout << dp[n - 1][m - 1] << "\n";
  return 0;
}
