#include <bits/stdc++.h>
using namespace std;
int dx8[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy8[8] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  file();
  fast();
  string te1, te2;
  cin >> te1 >> te2;
  int n;
  cin >> n;
  vector<int> team1(101), team2(101);
  vector<pair<int, pair<int, string>>> ans;
  map<pair<string, int>, int> vis;
  for (int i = 0; i < n; i++) {
    int t, m;
    char home, card;
    cin >> t >> home >> m >> card;
    if (card == 'r') {
      if (home == 'h') {
        ans.push_back({t, {m, te1}});
      } else {
        ans.push_back({t, {m, te2}});
      }
    } else {
      if (home == 'h') {
        team1[m]++;
        if (team1[m] == 2) {
          ans.push_back({t, {m, te1}});
        }
      } else {
        team2[m]++;
        if (team2[m] == 2) {
          ans.push_back({t, {m, te2}});
        }
      }
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    if (vis[{ans[i].second.second, ans[i].second.first}] == 1) continue;
    cout << ans[i].second.second << " " << ans[i].second.first << " "
         << ans[i].first << endl;
    vis[{ans[i].second.second, ans[i].second.first}] = 1;
  }
}
