#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return b / gcd(a, b) * a; }
string a, b;
int n;
int x[100], y[100];
int X[100], Y[100];
class state {
 public:
  string a;
  int num, time;
  state(string x, int s, int ss) {
    a = x;
    num = s;
    time = ss;
  }
  bool operator<(const state& b) const {
    if (b.time != time) return b.time > time;
    return b.num > num;
  }
};
int main() {
  cin >> a >> b;
  cin >> n;
  while (n--) {
    int m, num;
    string t, c;
    cin >> m >> t >> num >> c;
    int p = 1;
    if (c == "r") p = 2;
    if (t == "h") {
      if (x[num] < 2) {
        x[num] += p;
        X[num] = m;
      }
    } else {
      if (y[num] < 2) {
        y[num] += p;
        Y[num] = m;
      }
    }
  }
  vector<state> sss;
  for (int(i) = 0; i < int(100); ++i) {
    if (x[i] >= 2) sss.push_back(state(a, i, X[i]));
  }
  for (int(i) = 0; i < int(100); ++i)
    if (y[i] >= 2) sss.push_back(state(b, i, Y[i]));
  sort(sss.begin(), sss.end());
  for (int(i) = 0; i < int(sss.size()); ++i)
    cout << sss[i].a << " " << sss[i].num << " " << sss[i].time << endl;
  cin >> n;
}
