#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  map<char, string> ma;
  cin >> ma['h'];
  cin >> ma['a'];
  int t, n, p, h[100] = {0}, a[100] = {0};
  char c, d;
  cin >> n;
  while (n--) {
    cin >> t >> c >> p >> d;
    if (d == 'r') {
      if (c == 'h' && h[p] <= 1) {
        h[p] = 3;
        cout << ma[c] << " " << p << " " << t << "\n";
      } else if (c == 'a' && a[p] <= 1) {
        a[p] = 3;
        cout << ma[c] << " " << p << " " << t << "\n";
      }
    } else if (d == 'y') {
      if (c == 'h') {
        h[p]++;
        if (h[p] == 2) cout << ma[c] << " " << p << " " << t << "\n";
      } else if (c == 'a') {
        a[p]++;
        if (a[p] == 2) cout << ma[c] << " " << p << " " << t << "\n";
      }
    }
  }
  return 0;
}
