#include <bits/stdc++.h>
using namespace std;
const int MAXN = 128;
int hl, hr, n;
bool tag[2][MAXN];
vector<pair<pair<int, int>, int> > mirror[2];
vector<int> destination;
int getValue(vector<pair<pair<int, int>, int> > &v, int num, int den, int idx) {
  for (int i = 0; i < (int)v.size(); i++) {
    int x = v[i].first.first, y = v[i].first.second, value = v[i].second;
    if (x * den <= num && num <= y * den && !tag[idx][i]) {
      tag[idx][i] = true;
      return value;
    }
  }
  return -1;
}
int calc1(int x1, int y1, int x2, int y2) {
  int res = 0;
  for (int y = 100, cell = 1; y <= y2; y += 100, cell ^= 1) {
    int value = getValue(mirror[cell], 100000 * (y - y1), y2 - y1, cell);
    if (value == -1) {
      return -1;
    }
    res += value;
  }
  return res;
}
int calc2(int x1, int y1, int x2, int y2) {
  int res = 0;
  for (int y = 0, cell = 0; y >= y2; y -= 100, cell ^= 1) {
    int value = getValue(mirror[cell], 100000 * (y1 - y), y1 - y2, cell);
    if (value == -1) {
      return -1;
    }
    res += value;
  }
  return res;
}
int calc(int x1, int y1, int x2, int y2) {
  if (y1 < y2) {
    return calc1(x1, y1, x2, y2);
  } else if (y1 > y2) {
    return calc2(x1, y1, x2, y2);
  } else {
    return 0;
  }
}
int main() {
  scanf("%d%d%d", &hl, &hr, &n);
  int h1 = hr, h2 = hr;
  for (int i = 0; i < n; i++) {
    if (i & 1) {
      h1 = -h1;
      h2 = 200 - h2;
    } else {
      h1 = 200 - h1;
      h2 = -h2;
    }
    destination.push_back(h1);
    destination.push_back(h2);
  }
  sort(destination.begin(), destination.end());
  destination.erase(unique(destination.begin(), destination.end()),
                    destination.end());
  for (int i = 0; i < n; i++) {
    int value, x, y;
    char status[8];
    scanf("%d%s%d%d", &value, status, &x, &y);
    mirror[status[0] == 'T'].push_back(make_pair(make_pair(x, y), value));
  }
  int res = 0;
  for (vector<int>::const_iterator it = destination.begin();
       it != destination.end(); it++) {
    memset(tag, 0, sizeof(tag));
    res = max(res, calc(0, hl, 100000, *it));
  }
  printf("%d\n", res);
  return 0;
}
