#include <bits/stdc++.h>
using namespace std;
string home, away;
struct Node {
  int time;
  string name;
  string num;
  string type;
};
Node node[10000];
bool cmp(Node a, Node b) { return a.time < b.time; }
int main() {
  cin >> home >> away;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> node[i].time >> node[i].name >> node[i].num >> node[i].type;
  }
  sort(node, node + n, cmp);
  map<string, int> m;
  for (int i = 0; i < n; ++i) {
    string key = node[i].name + node[i].num;
    map<string, int>::iterator iter = m.find(key);
    int old = 0;
    if (iter != m.end()) {
      old = iter->second;
    }
    int next = 0;
    if (node[i].type == "y") {
      next = old + 1;
    } else {
      next = old + 2;
    }
    if (old < 2 && next >= 2) {
      if (node[i].name == "h")
        cout << home << " ";
      else
        cout << away << " ";
      cout << node[i].num << " " << node[i].time << endl;
    }
    m[key] = next;
  }
  return 0;
}
