#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> V(2);
  while (cin >> V[0] >> V[1]) {
    vector<vector<int> > T(2, vector<int>(100));
    int n;
    cin >> n;
    for (int it = 0; it < n; ++it) {
      int t;
      cin >> t;
      char type;
      cin >> type;
      int id;
      cin >> id;
      id--;
      char foul;
      cin >> foul;
      if (type == 'h')
        type = 0;
      else
        type = 1;
      if (foul == 'y')
        foul = 1;
      else
        foul = 2;
      if (T[type][id] == -1) continue;
      T[type][id] += foul;
      if (T[type][id] >= 2) {
        T[type][id] = -1;
        cout << V[type] << " " << id + 1 << " " << t << '\n';
      }
    }
  }
}
