#include <bits/stdc++.h>
using namespace std;
const int length = 100000;
const int height = 100;
int get_score(vector<pair<int, int> >& top, vector<pair<int, int> > floor,
              vector<int> top_score, vector<int> floor_score, double first_part,
              double part_len, int num_refl) {
  int floor_m = -1;
  int top_m = -1;
  int score = 0;
  double cur_pos = first_part;
  for (int i = 0; i < num_refl; i++) {
    int mir;
    if (i % 2 == 0) {
      for (mir = 0; mir < floor.size(); mir++) {
        if (floor[mir].first <= cur_pos && floor[mir].second >= cur_pos) {
          if (mir == floor_m) return 0;
          score += floor_score[mir];
          floor_m = mir;
          break;
        }
      }
      if (mir == floor.size()) return 0;
    } else {
      for (mir = 0; mir < top.size(); mir++) {
        if (top[mir].first <= cur_pos && top[mir].second >= cur_pos) {
          if (mir == top_m) return 0;
          score += top_score[mir];
          top_m = mir;
          break;
        }
      }
      if (mir == top.size()) return 0;
    }
    cur_pos += part_len;
  }
  return score;
}
int main() {
  int h1, h2, N;
  cin >> h1 >> h2 >> N;
  vector<pair<int, int> > top;
  vector<pair<int, int> > floor;
  vector<int> top_score;
  vector<int> floor_score;
  int a, b, score;
  char type;
  int max_len = 0;
  for (int ii = 0; ii < N; ii++) {
    cin >> score >> type >> a >> b;
    if (type == 'F') {
      floor.push_back(make_pair(a, b));
      floor_score.push_back(score);
    }
    if (type == 'T') {
      top.push_back(make_pair(a, b));
      top_score.push_back(score);
    }
    max_len = (max_len > (b - a)) ? max_len : (b - a);
  }
  int num_refl = 0;
  int max_score = 0;
  if (floor.size() && h1 > 0) {
    while (true) {
      num_refl++;
      double part_len = 0, first_part = 0;
      if (num_refl == 1) {
        part_len = 0;
        first_part = (double)h1 * length / (h1 + h2);
      } else {
        if (num_refl % 2 == 0) {
          part_len = (double)length /
                     ((double)(num_refl - 1) + ((double)(h1 + 100 - h2)) / 100);
        } else {
          part_len = (double)length /
                     ((double)(num_refl - 1) + ((double)(h1 + h2)) / 100);
        }
        first_part = part_len * (double)h1 / 100;
      }
      if (num_refl > 1 && (max_len > 5 * part_len)) break;
      int new_score = get_score(top, floor, top_score, floor_score, first_part,
                                part_len, num_refl);
      max_score = (max_score > new_score) ? max_score : new_score;
    }
  }
  num_refl = 0;
  if (top.size() && h1 < 100) {
    while (true) {
      num_refl++;
      double part_len = 0, first_part = 0;
      if (num_refl == 1) {
        part_len = 0;
        first_part = (double)(100 - h1) * length / (200 - h1 - h2);
      } else {
        if (num_refl % 2 == 0) {
          part_len = (double)length /
                     ((double)(num_refl - 1) + ((double)(100 - h1 + h2)) / 100);
        } else {
          part_len = (double)length /
                     ((double)(num_refl - 1) + ((double)(200 - h1 - h2)) / 100);
        }
        first_part = part_len * (double)(100 - h1) / 100;
      }
      if (num_refl > 1 && (max_len > 5 * part_len)) break;
      int new_score = get_score(floor, top, floor_score, top_score, first_part,
                                part_len, num_refl);
      max_score = (max_score > new_score) ? max_score : new_score;
    }
  }
  cout << max_score;
  return 0;
}
