#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
int hl, hr, n;
int mv[111], ma[111], mb[111];
bool mc[111];
int len = 100000;
int main() {
  cin >> hl >> hr >> n;
  hl = 100 - hl;
  hr = 100 - hr;
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    char h;
    cin >> mv[i] >> h >> ma[i] >> mb[i];
    mc[i] = h == 'F';
  }
  int r = 0;
  for (int(i) = (int)(1); (i) <= (int)(100); ++(i))
    for (int(f) = 0; (f) < (int)(2); ++(f)) {
      double a = i - 1;
      double b1 = !f ? hl / 100. : 1 - hl / 100.;
      double b2 = !(f ^ (i % 2 != 0) ^ 1) ? hr / 100. : 1 - hr / 100.;
      double t = len / (a + b1 + b2);
      if (abs(a + b1 + b2) < 1e-9) continue;
      vector<int> v(n, 0);
      int pt = 0;
      for (int(j) = (int)(1); (j) <= (int)(i); ++(j)) {
        double x = t * (j - (1 - b1));
        bool ft = ((f + (j - 1)) % 2) != 0;
        int kk = -1;
        for (int(k) = 0; (k) < (int)(n); ++(k))
          if (ma[k] - 1e-9 <= x && x < mb[k] + 1e-9 && mc[k] == ft) {
            kk = k;
            break;
          }
        if (kk == -1 || v[kk]) goto bad;
        v[kk] = 1;
        pt += mv[kk];
      }
      r = max(r, pt);
      cerr << i << ", " << f << ": " << pt << endl;
    bad:;
    }
  cout << r << endl;
  return 0;
}
