#include <bits/stdc++.h>
using namespace std;
int main() {
  string hm, aw;
  cin >> hm;
  cin >> aw;
  int n;
  cin >> n;
  int home[100];
  int away[100];
  int i, j, k;
  char a, b;
  vector<pair<int, int> > v;
  string s[n];
  for (i = 0; i < 100; i++) home[i] = away[i] = 0;
  for (i = 0; i < n; i++) {
    cin >> j;
    cin >> a;
    cin >> k;
    cin >> b;
    if (b == 'r') {
      if (a == 'h') {
        if (home[k] != 2) {
          home[k] = 2;
          s[v.size()] = hm;
          v.push_back({j, k});
        }
      } else {
        if (away[k] != 2) {
          away[k] = 2;
          s[v.size()] = aw;
          v.push_back({j, k});
        }
      }
    } else {
      if (a == 'h') {
        if (home[k] != 2) {
          home[k]++;
          if (home[k] == 2) {
            s[v.size()] = hm;
            v.push_back({j, k});
          }
        }
      } else {
        if (away[k] != 2) {
          away[k]++;
          if (away[k] == 2) {
            s[v.size()] = aw;
            v.push_back({j, k});
          }
        }
      }
    }
  }
  for (i = 0; i < v.size(); i++)
    cout << s[i] << " " << v[i].second << " " << (v[i].first) << "\n";
  return 0;
}
