#include <bits/stdc++.h>
using namespace std;
void solve();
int main() { solve(); }
int d[1000];
int s[1000];
set<pair<pair<int, int>, int>> t, b;
set<pair<pair<int, int>, int>>* other(set<pair<pair<int, int>, int>>* x) {
  return (x == &t) ? &b : &t;
}
namespace std {
template <>
struct hash<set<pair<pair<int, int>, int>>::iterator> {
  size_t operator()(set<pair<pair<int, int>, int>>::iterator t) const {
    return t->first.first * 10000 + t->first.second * 100 + t->second;
  }
};
}  // namespace std
void solve() {
  int l, r, n;
  cin >> l >> r >> n;
  for (int i = 0; i < n; ++i) {
    int v, ll, rr;
    char a;
    cin >> v >> a >> ll >> rr;
    pair<pair<int, int>, int> z = make_pair(make_pair(ll, rr), v);
    if (a == 'T')
      t.insert(z);
    else
      b.insert(z);
  }
  int ans = 0;
  for (int cnt = 1; cnt <= n; ++cnt) {
    unordered_set<set<pair<pair<int, int>, int>>::iterator> v;
    int pr = r;
    if (cnt % 2 == 1) pr = 100 - pr;
    int realFinish = pr - cnt * 100;
    int h = l - realFinish;
    set<pair<pair<int, int>, int>>* cur = &b;
    int sum = 0;
    bool ok = true;
    for (int i = 0; i < cnt; ++i) {
      int curH = l + i * 100;
      double s = curH * 100000 / (double)h;
      set<pair<pair<int, int>, int>>::iterator it =
          cur->upper_bound(make_pair(make_pair(s, 10000000), 10000000));
      if (it == cur->begin()) {
        ok = false;
        break;
      }
      --it;
      if (it->first.second < s) {
        ok = false;
        break;
      }
      v.insert(it);
      sum += it->second;
      cur = other(cur);
    }
    if (ok && v.size() == cnt) {
      ans = max(ans, sum);
    }
  }
  for (int cnt = 1; cnt <= n; ++cnt) {
    unordered_set<set<pair<pair<int, int>, int>>::iterator> v;
    int pr = r;
    if (cnt % 2 == 1) pr = 100 - pr;
    int realFinish = pr + cnt * 100;
    int h = realFinish - l;
    set<pair<pair<int, int>, int>>* cur = &t;
    int sum = 0;
    bool ok = true;
    for (int i = 0; i < cnt; ++i) {
      int curH = 100 - l + i * 100;
      double s = curH * 100000 / (double)h;
      set<pair<pair<int, int>, int>>::iterator it =
          cur->upper_bound(make_pair(make_pair(s, 10000000), 10000000));
      if (it == cur->begin()) {
        ok = false;
        break;
      }
      --it;
      if (it->first.second < s) {
        ok = false;
        break;
      }
      v.insert(it);
      sum += it->second;
      cur = other(cur);
    }
    if (ok && v.size() == cnt) {
      ans = max(ans, sum);
    }
  }
  cout << ans;
}
