#include <bits/stdc++.h>
using namespace std;
struct point {
  int t;
  char team;
  int num;
  char p;
};
int cmp(point a, point b) { return a.t < b.t; }
int main() {
  char a[1000], b[1000];
  scanf("%s", a);
  scanf("%s", b);
  int n;
  scanf("%d", &n);
  point c[100];
  for (int i = 0; i < n; i++) {
    cin >> c[i].t >> c[i].team >> c[i].num >> c[i].p;
  }
  sort(c, c + n, cmp);
  int d[5][150];
  memset(d, 0, sizeof(d));
  for (int i = 0; i < n; i++) {
    if (c[i].team == 'h') {
      if (d[0][c[i].num] >= 2) continue;
      if (c[i].p == 'y')
        d[0][c[i].num] += 1;
      else
        d[0][c[i].num] += 2;
      if (d[0][c[i].num] >= 2) printf("%s %d %d\n", a, c[i].num, c[i].t);
    } else {
      if (d[1][c[i].num] >= 2) continue;
      if (c[i].p == 'y')
        d[1][c[i].num] += 1;
      else
        d[1][c[i].num] += 2;
      if (d[1][c[i].num] >= 2) printf("%s %d %d\n", b, c[i].num, c[i].t);
    }
  }
  return 0;
}
