#include <bits/stdc++.h>
using namespace std;
bool m[200];
bool vis[200];
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int n;
  cin >> n;
  vector<pair<int, int> > h;
  vector<pair<int, int> > a;
  for (int i = 0; i < n; i++) {
    int t1, t2;
    char k1, k2;
    cin >> t1 >> k1 >> t2 >> k2;
    if (k1 == 'h') {
      if (m[t2]) {
        if (vis[t2]) continue;
        h.push_back({t2, t1});
        vis[t2] = 1;
        continue;
      }
      if (k2 == 'y') {
        m[t2] = 1;
      } else if (k2 == 'r') {
        if (vis[t2]) continue;
        h.push_back({t2, t1});
        vis[t2] = 1;
      }
    } else {
      if (m[t2 + 100]) {
        if (vis[t2 + 100]) continue;
        a.push_back({t2, t1});
        vis[t2 + 100] = 1;
        continue;
      }
      if (k2 == 'y') {
        m[t2 + 100] = 1;
      } else if (k2 == 'r') {
        if (vis[t2 + 100]) continue;
        a.push_back({t2, t1});
        vis[t2 + 100] = 1;
      }
    }
  }
  for (int i = 1; i <= 90; i++) {
    for (int j = 0; j < a.size(); j++) {
      if (a[j].second == i) {
        cout << s2 << " " << a[j].first << " " << a[j].second << endl;
        continue;
      }
    }
    for (int j = 0; j < h.size(); j++) {
      if (h[j].second == i) {
        cout << s1 << " " << h[j].first << " " << h[j].second << endl;
        continue;
      }
    }
  }
}
