#include <bits/stdc++.h>
using namespace std;
string home, away;
string ha[3];
int n;
int dd[3][100];
int dd1[3][100];
vector<pair<int, int> > ans[4];
void nhap() {
  cin >> ha[1] >> ha[2];
  cin >> n;
  int m, num;
  string t1, t2;
  memset(dd, 0, sizeof(dd));
  memset(dd1, 0, sizeof(dd1));
  for (int i = 1; i <= n; i++) {
    cin >> m >> t1 >> num >> t2;
    int type;
    if (t1 == "h")
      type = 1;
    else
      type = 2;
    if (t2 == "r" && !dd1[type][num]) {
      cout << ha[type] << " " << num << " " << m << endl;
      dd1[type][num] = 1;
      continue;
    }
    if (t2 == "y")
      if (dd[type][num] == 1 && !dd1[type][num]) {
        cout << ha[type] << " " << num << " " << m << endl;
        dd1[type][num] = 1;
      } else
        dd[type][num] = 1;
  }
}
void chuanbi() {}
void xuli() {}
int main() {
  ios_base::sync_with_stdio(0);
  nhap();
  chuanbi();
  xuli();
}
