#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int n;
  cin >> n;
  int ac[100][2] = {0}, bc[100][2] = {0};
  int i;
  for (i = 0; i < n; i++) {
    int mn, je;
    char t, cd;
    cin >> mn >> t >> je >> cd;
    if (cd == 'y') {
      if (t == 'h') {
        ac[je][0]++;
        if (ac[je][0] == 2 && ac[je][1] == 0) {
          cout << a << " " << je << " " << mn << endl;
          ac[je][0] = 0;
          ac[je][1] = 1;
        }
      } else {
        bc[je][0]++;
        if (bc[je][0] == 2 && bc[je][1] == 0) {
          cout << b << " " << je << " " << mn << endl;
          bc[je][0] = 0;
          bc[je][1] = 1;
        }
      }
    } else {
      if (t == 'h') {
        if (ac[je][1] == 0) {
          cout << a << " " << je << " " << mn << endl;
          ac[je][0] = 0;
          ac[je][1] = 1;
        }
      } else {
        if (bc[je][1] == 0) {
          cout << b << " " << je << " " << mn << endl;
          bc[je][0] = 0;
          bc[je][1] = 1;
        }
      }
    }
  }
}
