#include <bits/stdc++.h>
using namespace std;
struct table {
  int number;
  int time;
  string comand_name;
  bool operator<(const table& a) const { return time < a.time; }
};
int main() {
  vector<table> c(100);
  string s, s1;
  getline(cin, s);
  getline(cin, s1);
  int n;
  cin >> n;
  int t[100], num[100];
  char a[100], b[100];
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> a[i] >> num[i] >> b[i];
  }
  int k = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if ((a[j] == a[i] && b[j] == b[i] && num[j] == num[i]) && b[i] == 'y') {
        if (a[j] == 'h')
          c[k].comand_name = s;
        else
          c[k].comand_name = s1;
        c[k].number = num[j];
        c[k].time = t[j];
        k++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (b[i] == 'r') {
      if (a[i] == 'h')
        c[k].comand_name = s;
      else
        c[k].comand_name = s1;
      c[k].number = num[i];
      c[k].time = t[i];
      k++;
    }
  }
  int z = 0;
  sort(c.begin(), c.end());
  for (int i = 0; i < 100; i++) {
    {
      if (c[i].time >= 1 && c[i].time <= 90) {
        z = 0;
        for (int j = 0; j < i; j++) {
          if (c[j].number == c[i].number &&
              c[j].comand_name == c[i].comand_name)
            z++;
        }
        if (z == 0) {
          cout << c[i].comand_name << " " << c[i].number << " " << c[i].time;
          cout << endl;
        }
      }
    }
  }
}
