#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int cost[N][2], timee, tmm, num, clr, n;
char ha, arr[25];
string tm1, tm2;
int main() {
  scanf(" %s", &arr);
  tm1 = arr;
  scanf(" %s%d", &arr, &n);
  tm2 = arr;
  while (n--) {
    scanf("%d %c%d %c", &timee, &tmm, &num, &clr);
    if (clr == 'y') {
      if (tmm == 'h') {
        cost[num][0]++;
      } else {
        cost[num][1]++;
      }
    } else {
      if (tmm == 'h') {
        cost[num][0] += 2;
      } else {
        cost[num][1] += 2;
      }
    }
    if (cost[num][0] > 1) {
      cout << tm1 << " " << num << " " << timee << '\n';
      cost[num][0] = -1e9;
    }
    if (cost[num][1] > 1) {
      cout << tm2 << " " << num << " " << timee << '\n';
      cost[num][1] = -1e9;
    }
  }
  return 0;
}
