#include <bits/stdc++.h>
using namespace std;
char home[21];
char away[21];
int h[100];
int a[100];
struct node {
  int t;
  char team;
  int player;
  char type;
} foul[100];
int compare(const void *a, const void *b) {
  struct node *x, *y;
  x = (struct node *)a;
  y = (struct node *)b;
  return x->t - y->t;
}
int main() {
  int i, j, p, N, M, R, T, fouls, player;
  scanf("%s", home);
  scanf("%s", away);
  scanf("%d", &fouls);
  for (i = 0; i < fouls; i++) {
    scanf("%d", &foul[i].t);
    getchar();
    foul[i].team = getchar();
    scanf("%d", &foul[i].player);
    getchar();
    foul[i].type = getchar();
  }
  qsort(foul, fouls, sizeof(struct node), compare);
  for (i = 0; i < fouls; i++) {
    p = foul[i].player;
    if (foul[i].team == 'h') {
      if ((h[p] == 1) || (h[p] == 0 && foul[i].type == 'r')) {
        printf("%s %d %d\n", home, foul[i].player, foul[i].t);
        h[p] = 3;
      } else if (h[p] == 0)
        h[p] = 1;
    } else {
      if ((a[p] == 1) || (a[p] == 0 && foul[i].type == 'r')) {
        printf("%s %d %d\n", away, foul[i].player, foul[i].t);
        a[p] = 3;
      } else if (a[p] == 0)
        a[p] = 1;
    }
  }
  return 0;
}
