#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int n;
int t;
string w;
int nom;
string rr;
int resa[100];
int resh[100];
vector<pair<pair<string, int>, int> > ares;
int main() {
  cin >> s1 >> s2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t >> w >> nom >> rr;
    if (w == "h") {
      if (rr == "y") resa[nom]++;
      if (resa[nom] == 2 || rr == "r" && resa[nom] < 100) {
        resa[nom] = 100;
        ares.push_back(make_pair(make_pair(s1, nom), t));
      }
    } else {
      if (rr == "y") resh[nom]++;
      if (resh[nom] == 2 || rr == "r" && resh[nom] < 100) {
        resh[nom] = 100;
        ares.push_back(make_pair(make_pair(s2, nom), t));
      }
    }
  }
  for (int i = 0; i < ares.size(); i++) {
    cout << ares[i].first.first << " " << ares[i].first.second << " "
         << ares[i].second << endl;
  }
}
