#include <bits/stdc++.h>
using namespace std;
int t1[100], t2[100];
int c1[105], c2[105];
char s1[30], s2[30];
int main() {
  int n;
  int i, j;
  scanf("%s%s", s1, s2);
  scanf("%d", &n);
  int t, num;
  char team, card;
  for (i = 1; i <= n; i++) {
    scanf("%d %c %d %c", &t, &team, &num, &card);
    if (team == 'h') {
      if (c1[num] < 2) {
        c1[num]++;
        if (card == 'r') c1[num]++;
        if (c1[num] >= 2) {
          t1[t] = num;
        }
      }
    } else {
      if (c2[num] < 2) {
        c2[num]++;
        if (card == 'r') c2[num]++;
        if (c2[num] >= 2) {
          t2[t] = num;
        }
      }
    }
  }
  for (i = 1; i <= 90; i++) {
    if (t1[i]) {
      printf("%s %d %d\n", s1, t1[i], i);
    }
    if (t2[i]) {
      printf("%s %d %d\n", s2, t2[i], i);
    }
  }
  return 0;
}
