#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  vector<string> teamNames(2);
  cin >> teamNames[0] >> teamNames[1];
  int n;
  cin >> n;
  vector<vector<pair<int, int> > > ts(
      2, vector<pair<int, int> >(99 + 1, make_pair(0, 0)));
  for (int i = 0; i < n; i++) {
    int t;
    string teamType;
    int m;
    string color;
    cin >> t >> teamType >> m >> color;
    int team = 0;
    if (teamType == "a") {
      team = 1;
    }
    if (ts[team][m].second == 1) {
      continue;
    }
    if (color == "r") {
      if (ts[team][m].second == 0) {
        cout << teamNames[team] << " " << m << " " << t << endl;
        ts[team][m].second = 1;
      }
    } else {
      if (ts[team][m].first == 0) {
        ts[team][m].first++;
      } else if (ts[team][m].first == 1) {
        ts[team][m].first++;
        ts[team][m].second = 1;
        cout << teamNames[team] << " " << m << " " << t << endl;
      }
    }
  }
  return 0;
}
