#include <bits/stdc++.h>
using namespace std;
int main() {
  string h, a;
  int n;
  int hcards[100];
  int acards[100];
  int time;
  char team;
  int num;
  char type;
  for (int i = 0; i < 100; i++) {
    hcards[i] = 0;
    acards[i] = 0;
  }
  cin >> h >> a >> n;
  for (int i = 0; i < n; ++i) {
    cin >> time >> team >> num >> type;
    if (team == 'h') {
      if ((hcards[num] == 1) || (hcards[num] < 2 && type == 'r')) {
        hcards[num] = 2;
        cout << h << " " << num << " " << time << endl;
      } else if (hcards[num] == 0)
        hcards[num] = 1;
    } else {
      if ((acards[num] == 1) || (acards[num] < 2 && type == 'r')) {
        acards[num] = 2;
        cout << a << " " << num << " " << time << endl;
      } else if (acards[num] == 0)
        acards[num] = 1;
    }
  }
  return 0;
};
