#include <bits/stdc++.h>
using namespace std;
string home, away;
int nof;
int minute, player;
char team, card;
int homePlayers[101];
int awayPlayers[101];
int thomePlayers[101];
int tawayPlayers[101];
int process(int m, char t, int p, char c) {
  if (t == 'a') {
    if (c == 'y') {
      if (awayPlayers[p] >= 2) return 0;
      awayPlayers[p]++;
      tawayPlayers[p] = m;
    } else {
      if (awayPlayers[p] >= 2) return 0;
      awayPlayers[p] += 2;
      tawayPlayers[p] = m;
    }
  } else {
    if (c == 'y') {
      if (homePlayers[p] >= 2) return 0;
      homePlayers[p]++;
      thomePlayers[p] = m;
    } else {
      if (homePlayers[p] >= 2) return 0;
      homePlayers[p] += 2;
      thomePlayers[p] = m;
    }
  }
  return 0;
}
int main() {
  cin >> home >> away;
  cin >> nof;
  for (int i = 0; i < nof; ++i) {
    cin >> minute >> team >> player >> card;
    process(minute, team, player, card);
  }
  vector<pair<int, pair<int, string> > > res;
  for (int i = 0; i < 101; ++i) {
    if (homePlayers[i] >= 2) {
      res.push_back(make_pair(thomePlayers[i], make_pair(i, home)));
    }
  }
  for (int i = 0; i < 101; ++i) {
    if (awayPlayers[i] >= 2) {
      res.push_back(make_pair(tawayPlayers[i], make_pair(i, away)));
    }
  }
  sort(res.begin(), res.end());
  for (int i = 0; i < res.size(); ++i) {
    cout << res[i].second.second << " ";
    cout << res[i].second.first << " ";
    cout << res[i].first << endl;
  }
  return 0;
}
