#include <bits/stdc++.h>
using namespace std;
vector<int> h(101, 0), a(101, 0), hh(101, 0), aa(101, 0);
int main() {
  string home, away;
  cin >> home >> away;
  int n, i, j, k;
  cin >> n;
  for (i = 0; i < n; i++) {
    int t;
    cin >> t;
    char team, card;
    int playernum;
    cin >> team >> playernum >> card;
    if (team == 'a') {
      if (card == 'r')
        a[playernum] += 2;
      else
        a[playernum] += 1;
      if (a[playernum] >= 2 and aa[playernum] == 0) {
        cout << away << " " << playernum << " " << t << endl;
        aa[playernum] = 1;
      }
    } else {
      if (card == 'r')
        h[playernum] += 2;
      else
        h[playernum] += 1;
      if (h[playernum] >= 2 and hh[playernum] == 0) {
        cout << home << " " << playernum << " " << t << endl;
        hh[playernum] = 1;
      }
    }
  }
  return 0;
}
