#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int N = 500;
long long f[N][N];
vector<pair<int, int> > row[N][N];
vector<pair<int, int> > col[N][N];
long long s_r[N][N];
long long s_c[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int m;
  cin >> m;
  int k;
  cin >> k;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) f[i][j] = inf;
  f[0][0] = 0;
  for (int i = 0; i < k; ++i) {
    int x, y;
    cin >> x >> y;
    int d, T;
    cin >> d >> T;
    int C;
    cin >> C;
    int dx[] = {0, d, d, 0};
    int dy[] = {0, -d, 0, d};
    vector<pair<int, int> > robot;
    for (int j = 0; j < 4; ++j) {
      int xx = x + dx[j];
      int yy = y + dy[j];
      if ((T + j) % 4 == (xx + yy) % 4 && T <= xx + yy)
        robot.emplace_back(xx, yy);
    }
    sort(robot.begin(), robot.end());
    if (robot.empty()) continue;
    if (robot.size() == 1) {
      s_r[robot[0].first][robot[0].second] += C;
      s_c[robot[0].first][robot[0].second] += C;
      continue;
    }
    int r[] = {robot[0].first, robot[1].first};
    int c[] = {robot[0].second, robot[1].second};
    s_r[r[0]][c[0]] += C;
    s_c[r[0]][c[0]] += C;
    if (r[0] == r[1]) {
      row[r[1]][c[1]].emplace_back(c[0], C);
      s_r[r[1]][c[1]] += C;
      continue;
    }
    if (c[0] == c[1]) {
      col[r[1]][c[1]].emplace_back(r[0], C);
      s_c[r[1]][c[1]] += C;
      continue;
    }
    s_r[r[1]][c[1]] += C, s_c[r[1]][c[1]] += C;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      long long trans = 0;
      for (int x = j + 1; x < m; ++x) {
        trans += s_c[i][x];
        for (pair<int, int> p : row[i][x])
          if (p.first < j) trans += p.second;
        if (f[i][x] > f[i][j] + trans) f[i][x] = f[i][j] + trans;
      }
      trans = 0;
      for (int x = i + 1; x < n; ++x) {
        trans += s_r[x][j];
        for (pair<int, int> p : col[x][j])
          if (p.first < i) trans += p.second;
        if (f[x][j] > f[i][j] + trans) f[x][j] = f[i][j] + trans;
      }
    }
  cout << f[n - 1][m - 1] << "\n";
}
