#include <bits/stdc++.h>
using namespace std;
struct info {
  int red, yel, chk;
} v[1000];
struct info1 {
  int red, yel, chk;
} v1[1000];
int main() {
  string home, away;
  cin >> home >> away;
  int in, n, i, j, time, number;
  char formation, card;
  cin >> n;
  while (n--) {
    cin >> time >> formation >> number >> card;
    if (formation == 'h') {
      if (card == 'y') {
        v[number].yel++;
      } else {
        v[number].red++;
      }
      if ((v[number].yel == 2 || v[number].red == 1) && v[number].chk == 0) {
        cout << home << " " << number << " " << time << endl;
        v[number].chk = 1;
      }
    } else {
      if (card == 'y') {
        v1[number].yel++;
      } else {
        v1[number].red++;
      }
      if ((v1[number].yel == 2 || v1[number].red == 1) && v1[number].chk == 0) {
        cout << away << " " << number << " " << time << endl;
        v1[number].chk = 1;
      }
    }
  }
  return 0;
}
