#include <bits/stdc++.h>
using namespace std;
struct point {
  int l, r, v;
} a[2][104];
int h1, h2, n, fn, tn, bb[2][105];
int main() {
  cin >> h1 >> h2 >> n;
  h1 = 100 - h1;
  h2 = 100 - h2;
  for (int i = 0; i < n; i++) {
    int v, l, r;
    char c;
    scanf("%d %c %d %d", &v, &c, &l, &r);
    if (c == 'F') {
      a[0][fn].l = l;
      a[0][fn].r = r;
      a[0][fn++].v = v;
    } else {
      a[1][tn].l = l;
      a[1][tn].r = r;
      a[1][tn++].v = v;
    }
  }
  int ans = 0;
  for (int i = 1; i <= 101; i++) {
    bool br = true;
    int as = 0;
    memset(bb, 0, sizeof(bb));
    int kk;
    if (i & 1)
      kk = i * 100 + (100 - h2) - h1;
    else
      kk = i * 100 + h2 - h1;
    for (int j = 0; j < i; j++) {
      double t = ((double)100 * (j + 1) - h1) / (((double)kk) / (100000));
      if (j & 1) {
        bool b = false;
        for (int k = 0; k < tn; k++)
          if (a[1][k].l <= t && a[1][k].r >= t) {
            if (bb[1][k]) break;
            bb[1][k] = 1;
            as += a[1][k].v;
            b = true;
            break;
          }
        if (!b) {
          br = false;
          break;
        }
      } else {
        bool b = false;
        for (int k = 0; k < fn; k++)
          if (a[0][k].l <= t && a[0][k].r >= t) {
            if (bb[0][k]) break;
            bb[0][k] = 1;
            as += a[0][k].v;
            b = true;
            break;
          }
        if (!b) {
          br = false;
          break;
        }
      }
    }
    if (!br) continue;
    ans = max(ans, as);
  }
  h1 = 100 - h1;
  h2 = 100 - h2;
  for (int i = 1; i <= 101; i++) {
    bool br = true;
    int as = 0;
    memset(bb, 0, sizeof(bb));
    int kk;
    if (i & 1)
      kk = i * 100 + (100 - h2) - h1;
    else
      kk = i * 100 + h2 - h1;
    for (int j = 0; j < i; j++) {
      double t = ((double)100 * (j + 1) - h1) / (((double)kk) / (100000));
      if (!(j & 1)) {
        bool b = false;
        for (int k = 0; k < tn; k++)
          if (a[1][k].l <= t && a[1][k].r >= t) {
            if (bb[1][k]) break;
            bb[1][k] = 1;
            as += a[1][k].v;
            b = true;
            break;
          }
        if (!b) {
          br = false;
          break;
        }
      } else {
        bool b = false;
        for (int k = 0; k < fn; k++)
          if (a[0][k].l <= t && a[0][k].r >= t) {
            if (bb[0][k]) break;
            bb[0][k] = 1;
            as += a[0][k].v;
            b = true;
            break;
          }
        if (!b) {
          br = false;
          break;
        }
      }
    }
    if (!br) continue;
    ans = max(ans, as);
  }
  cout << ans;
}
