#include <bits/stdc++.h>
using namespace std;
void dbg(int x) { cout << "x is " << x << "\n"; }
unordered_map<int, pair<int, bool>> home;
unordered_map<int, pair<int, bool>> away;
void solve() {
  string a, b;
  cin >> a >> b;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t, m;
    char c, x;
    cin >> t >> c >> m >> x;
    if (c == 'h') {
      if (x == 'r') {
        if (!home[m].second) {
          cout << a << " " << m << " " << t << "\n";
          home[m].second = 1;
        }
      } else {
        home[m].first++;
        if (home[m].first == 2 && !home[m].second) {
          cout << a << " " << m << " " << t << "\n";
          home[m].second = 1;
        }
      }
    } else {
      if (x == 'r') {
        if (!away[m].second) {
          cout << b << " " << m << " " << t << "\n";
          away[m].second = 1;
        }
      } else {
        away[m].first++;
        if (away[m].first == 2 && !away[m].second) {
          cout << b << " " << m << " " << t << "\n";
          away[m].second = 1;
        }
      }
    }
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
