#include <bits/stdc++.h>
int main() {
  char hname[50], aname[50];
  int h[100], a[100];
  int n, i, time, num;
  char team, foul;
  scanf("%s", hname);
  scanf("%s", aname);
  scanf("%d", &n);
  memset(h, 0, sizeof(h));
  memset(a, 0, sizeof(h));
  for (i = 0; i < n; i++) {
    scanf("%d %c %d %c", &time, &team, &num, &foul);
    if (team == 'h') {
      if (h[num] == -1) continue;
      if (foul == 'y')
        h[num]++;
      else
        h[num] += 2;
      if (h[num] >= 2) {
        printf("%s %d %d\n", hname, num, time);
        h[num] = -1;
      }
    } else {
      if (a[num] == -1) continue;
      if (foul == 'y')
        a[num]++;
      else
        a[num] += 2;
      if (a[num] >= 2) {
        printf("%s %d %d\n", aname, num, time);
        a[num] = -1;
      }
    }
  }
  return 0;
}
