#include <bits/stdc++.h>
using namespace std;
int main() {
  string ho, aw;
  vector<string> ANS;
  map<int, int> ans, ans2, d, d2;
  cin >> ho >> aw;
  int n;
  cin >> n;
  while (n--) {
    int t, m;
    char h, l;
    cin >> t >> h >> m >> l;
    if (h == 'h') {
      if (l == 'y') d[m]++;
      if ((l == 'r' || d[m] >= 2) && (ans[m] == 0)) {
        ans[m] = 1;
        string tm = ho, y, x;
        tm += " ";
        stringstream ss, ss2;
        ss << m;
        ss >> y;
        tm += y;
        tm += " ";
        ss2 << t;
        ss2 >> x;
        tm += x;
        ANS.push_back(tm);
      }
    } else {
      if (l == 'y') d2[m]++;
      if ((l == 'r' || d2[m] >= 2) && (ans2[m] == 0)) {
        ans2[m] = 1;
        string tm = aw, x, y;
        tm += " ";
        stringstream ss, ss2;
        ss << m;
        ss >> y;
        tm += y;
        tm += " ";
        ss2 << t;
        ss2 >> x;
        tm += x;
        ANS.push_back(tm);
      }
    }
  }
  for (int i = 0; i < ANS.size(); i++) cout << ANS[i] << endl;
  return 0;
}
