#include <bits/stdc++.h>
using namespace std;
class Mirror {
 public:
  Mirror() {}
  Mirror(int x1, int x2) : x1(x1), x2(x2) {}
  int score;
  char pos;
  int x1, x2;
  bool operator<(const Mirror &m) const { return x1 < m.x1; }
  template <class T>
  bool contains(T x) const {
    return x1 <= x && x <= x2;
  }
};
istream &operator>>(istream &is, Mirror &m) {
  is >> m.score >> m.pos >> m.x1 >> m.x2;
  return is;
}
ostream &operator<<(ostream &os, const Mirror &m) {
  os << m.score << " \"" << m.pos << "\" " << m.x1 << " " << m.x2;
  return os;
}
bool comp_x1(const Mirror &m1, const Mirror &m2) { return m1.x1 < m2.x1; }
bool comp_x2(const Mirror &m1, const Mirror &m2) { return m1.x2 < m2.x2; }
template <class ForwardIterator, class T>
ForwardIterator check_mirror_hit(ForwardIterator first, ForwardIterator last,
                                 const T &val) {
  Mirror m((int)val, (int)val);
  ForwardIterator it = lower_bound(first, last, m, comp_x2);
  if (it != last) {
    if (it->x1 > val) {
      it = last;
    }
  }
  return it;
}
int check_line(vector<Mirror>::iterator top_first,
               vector<Mirror>::iterator top_last,
               vector<Mirror>::iterator bot_first,
               vector<Mirror>::iterator bot_last, int hl, int hr) {
  struct level {
    vector<Mirror>::iterator first, last;
  };
  level levels[2];
  levels[0].first = top_first;
  levels[0].last = top_last;
  levels[1].first = bot_first;
  levels[1].last = bot_last;
  int level_i = 0;
  int full_rise = hr - hl;
  int rise = (100 - hl);
  int val = 0;
  while (rise < full_rise) {
    double x = rise * 100000.0 / full_rise;
    vector<Mirror>::iterator &first = levels[level_i].first;
    vector<Mirror>::iterator &last = levels[level_i].last;
    first = check_mirror_hit(first, last, x);
    if (first == last) {
      return 0;
    }
    val += first->score;
    first++;
    rise += 100;
    level_i ^= 1;
  }
  return val;
}
int max_first(vector<Mirror>::iterator top_first,
              vector<Mirror>::iterator top_last,
              vector<Mirror>::iterator bot_first,
              vector<Mirror>::iterator bot_last, int hl, int hr) {
  if (top_first == top_last) return 0;
  Mirror &m = *top_first;
  int max_y = 100000 * (100 - hl) / m.x1 + hl;
  int min_y = 100000 * (100 - hl) / m.x2 + hl;
  int deltas[] = {2 * hr, 2 * (100 - hr)};
  int delta_i = 0;
  int level = max_y / 100;
  int target = level * 100;
  if (level % 2 != 0) {
    delta_i = 1;
    target += 100 - hr;
  } else {
    target += hr;
  }
  int val = 0;
  while (target >= min_y) {
    if (target <= max_y) {
      val = max(val, check_line(top_first, top_last, bot_first, bot_last, hl,
                                target));
    }
    target -= deltas[delta_i];
    delta_i ^= 1;
  }
  return val;
}
void trim_mirrors(vector<Mirror> &m, int min_x) {
  vector<Mirror>::iterator i = m.begin();
  for (; i != m.end() && i->x2 < min_x; ++i) {
  }
  m.erase(m.begin(), i);
  if (i != m.end()) {
    if (i->contains(min_x)) {
      i->x1 = min_x;
    }
  }
}
void optimize_mirrors(vector<Mirror> &top, vector<Mirror> &bot, int hl) {
  int max_bounces = 2 * min(top.size(), bot.size());
  if (top.size() != bot.size()) {
    max_bounces++;
  }
  int max_target = 100 * (1 + max_bounces);
  int min_target = -100 * max_bounces;
  if (top.size() != 0) {
    int min_top_x = (100 - hl) * 100000 / (max_target - hl);
    trim_mirrors(top, min_top_x);
  }
  if (bot.size() != 0) {
    int min_bot_x = hl * 100000 / (hl - min_target);
    trim_mirrors(bot, min_bot_x);
  }
}
int main() {
  int i;
  int hl, hr, n;
  cin >> hl >> hr >> n;
  vector<Mirror> tops, bottoms;
  for (i = 0; i < n; i++) {
    Mirror m;
    cin >> m;
    if (m.pos == 'T') {
      tops.push_back(m);
    } else {
      bottoms.push_back(m);
    }
  }
  sort(tops.begin(), tops.end());
  sort(bottoms.begin(), bottoms.end());
  optimize_mirrors(tops, bottoms, hl);
  int val = 0;
  for (vector<Mirror>::iterator it = tops.begin(); it != tops.end(); ++it) {
    val = max(
        val, max_first(it, tops.end(), bottoms.begin(), bottoms.end(), hl, hr));
  }
  for (vector<Mirror>::iterator it = bottoms.begin(); it != bottoms.end();
       ++it) {
    val = max(val, max_first(it, bottoms.end(), tops.begin(), tops.end(),
                             100 - hl, 100 - hr));
  }
  cout << val << endl;
  return 0;
}
