#include <bits/stdc++.h>
using namespace std;
vector<pair<string, pair<int, int> > > mp;
int a[100], b[100];
bool used[100], used2[100];
int main() {
  string s, s2;
  cin >> s >> s2;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t, m;
    char d, c;
    cin >> t >> c >> m >> d;
    if (c == 'h') {
      if (d == 'r' && !used[m]) {
        used[m] = 1;
        mp.push_back(make_pair(s, make_pair(m, t)));
      } else if (d == 'y' && !used[m]) {
        a[m]++;
        if (a[m] == 2) {
          used[m] = 1;
          mp.push_back(make_pair(s, make_pair(m, t)));
        }
      }
    } else {
      if (d == 'r' && !used2[m]) {
        used2[m] = 1;
        mp.push_back(make_pair(s2, make_pair(m, t)));
      } else if (d == 'y' && !used2[m]) {
        b[m]++;
        if (b[m] == 2) {
          used2[m] = 1;
          mp.push_back(make_pair(s2, make_pair(m, t)));
        }
      }
    }
  }
  for (int i = 0; i < mp.size(); i++) {
    cout << mp[i].first << " " << mp[i].second.first << " "
         << mp[i].second.second << endl;
  }
}
