#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
using namespace std;
char home[25];
char away[25];
int ho[100];
int aw[100];
int main() {
  memset(ho, 0, sizeof(ho));
  memset(aw, 0, sizeof(aw));
  scanf("%s %s", home, away);
  int n;
  scanf("%d", &n);
  int a, b;
  char c, d;
  for (int i = 0; i < n; ++i) {
    scanf("%d %c %d %c", &a, &c, &b, &d);
    {
      if (c == 'h') {
        if (ho[b] == 3) continue;
        if (d == 'r' && ho[b] != 3) {
          ho[b] = 3;
          printf("%s %d %d\n", home, b, a);
          continue;
        }
        if (ho[b] == 1 && d == 'y') {
          ho[b] = 3;
          printf("%s %d %d\n", home, b, a);
        } else if (d == 'y') {
          ho[b] = 1;
          continue;
        }
      } else {
        if (aw[b] == 3) continue;
        if (d == 'r' && aw[b] != 3) {
          aw[b] = 3;
          printf("%s %d %d\n", away, b, a);
          continue;
        }
        if (aw[b] == 1 && d == 'y') {
          aw[b] = 3;
          printf("%s %d %d\n", away, b, a);
        } else if (d == 'y') {
          aw[b] = 1;
          continue;
        }
      }
    }
  }
  return 0;
}
