#include <bits/stdc++.h>
using namespace std;
template <class T>
void max_swap(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void min_swap(T& a, const T& b) {
  a = min(a, b);
}
template <class T>
void sort(vector<T>& c) {
  sort(c.begin(), c.end());
}
template <class T>
void uniq(vector<T>& c) {
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
}
template <class T>
string to_s(const T& a) {
  ostringstream os;
  os << a;
  return os.str();
}
template <class T>
T to_T(const string& s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
  os << "( " << p.first << ", " << p.second << " )";
  return os;
}
template <class T>
void print(T a, int n, const string& deli = " ", int br = 1) {
  for (int i = 0; i < n; ++i) {
    cout << a[i];
    if (i + 1 != n) cout << deli;
  }
  while (br--) cout << endl;
}
template <class T>
void print(const T& c, const string& deli = " ", int br = 1) {
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) {
    cout << *it;
    if (++it != c.end()) cout << deli;
    --it;
  }
  while (br--) cout << endl;
}
template <class T>
void print2d(T a, int w, int h, int width = -1, int br = 1) {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (width != -1) cout.width(width);
      cout << a[i][j] << ' ';
    }
    cout << endl;
  }
  while (br--) cout << endl;
}
template <class T>
void input(T& a, int n) {
  for (int i = 0; i < n; ++i) cin >> a[i];
}
template <class T>
void input(T* a, int n) {
  for (int i = 0; i < n; ++i) cin >> a[i];
}
void fast_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
bool valid(int x, int y, int w, int h) {
  return 0 <= x && x < w && 0 <= y && y < h;
}
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const double PI = acos(-1.0);
const int mod = 1000000007;
const int box_w = ((long long)(1e5));
const int box_h = 100;
struct Mirror {
  int l, r, score;
};
int simulate(int reflects, int hl, int hr, const vector<Mirror>& t,
             const vector<Mirror>& f) {
  int full = reflects - 1;
  int sum_h =
      full * box_h + (reflects % 2 == 0 ? hr : box_h - hr) + (box_h - hl);
  double inc = (double)box_w / sum_h;
  int sum_score = 0;
  vector<Mirror> mir[2] = {t, f};
  bool used[2][111];
  memset(used, 0, sizeof(used));
  for (int i = 0, y = (box_h - hl); i < reflects; ++i, y += box_h) {
    vector<Mirror>& m = mir[i & 1];
    bool* u = used[i & 1];
    double x = inc * y;
    int k = -1;
    for (int j = 0; j < m.size(); ++j) {
      const double eps = 1e-7;
      if (m[j].l - eps < x && x < m[j].r + eps) {
        k = j;
        break;
      }
    }
    if (k == -1 || u[k]) return 0;
    u[k] = true;
    sum_score += m[k].score;
  }
  return sum_score;
}
int main() {
  int hl, hr, n;
  cin >> hl >> hr >> n;
  vector<Mirror> t, f;
  for (int i = 0; i < (int)(n); ++i) {
    int v, a, b;
    char c;
    cin >> v >> c >> a >> b;
    Mirror mi = (Mirror){a, b, v};
    if (c == 'T')
      t.push_back(mi);
    else
      f.push_back(mi);
  }
  int res = 0;
  for (int ref = 1; ref <= n; ++ref) {
    max_swap(res, simulate(ref, hl, hr, t, f));
    max_swap(res, simulate(ref, box_h - hl, box_h - hr, f, t));
  }
  cout << res << endl;
}
