#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000,100000000000")
using namespace std;
int v[2][105];
bool b[2][105];
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    char c, c1;
    int t;
    int nom;
    cin >> t >> c >> nom >> c1;
    if (c == 'h') {
      ++v[0][nom];
      if (!b[0][nom] && (v[0][nom] == 2 || c1 == 'r')) {
        cout << s1 << ' ' << nom << ' ' << t << '\n';
        b[0][nom] = true;
      }
    } else {
      ++v[1][nom];
      if (!b[1][nom] && (v[1][nom] == 2 || c1 == 'r')) {
        cout << s2 << ' ' << nom << ' ' << t << '\n';
        b[1][nom] = true;
      }
    }
  }
  return 0;
}
