#include <bits/stdc++.h>
using namespace std;
class player {
 public:
  char c;
  int n;
  int card;
  bool got;
  player() {}
  ~player() {}
};
int main() {
  string h, g;
  cin >> h >> g;
  int n;
  cin >> n;
  int num, mom;
  char com, col;
  vector<player> home;
  vector<player> guest;
  for (int i = 0; i < n; i++) {
    cin >> mom >> com >> num >> col;
    if (com == 'h') {
      int f = 0;
      for (int j = 0; j < home.size(); j++) {
        if (home[j].n == num) {
          if (home[j].got == false) {
            if (col == 'r') {
              home[j].got = true;
              cout << h << " " << num << " " << mom << endl;
            } else {
              home[j].card++;
              if (home[j].card == 2) {
                home[j].got = true;
                cout << h << " " << num << " " << mom << endl;
              }
            }
          }
          f = 1;
          break;
        }
      }
      if (f == 0) {
        player np;
        np.c = com;
        if (col == 'y') {
          np.card = 1;
          np.got = false;
        } else {
          np.got = true;
          cout << h << " " << num << " " << mom << endl;
        }
        np.n = num;
        home.push_back(np);
      }
    } else {
      int f = 0;
      for (int j = 0; j < guest.size(); j++) {
        if (guest[j].n == num) {
          if (guest[j].got == false) {
            if (col == 'r') {
              guest[j].got = true;
              cout << g << " " << num << " " << mom << endl;
            } else {
              guest[j].card++;
              if (guest[j].card == 2) {
                guest[j].got = true;
                cout << g << " " << num << " " << mom << endl;
              }
            }
          }
          f = 1;
          break;
        }
      }
      if (f == 0) {
        player np;
        np.c = com;
        if (col == 'y') {
          np.card = 1;
          np.got = false;
        } else {
          np.got = true;
          cout << g << " " << num << " " << mom << endl;
        }
        np.n = num;
        guest.push_back(np);
      }
    }
  }
  return 0;
}
