#include <bits/stdc++.h>
using namespace std;
int playersa[100];
int playersh[100];
int main() {
  string home, away;
  cin >> home >> away;
  int x;
  cin >> x;
  while (x--) {
    int minu, pl;
    char r, t;
    cin >> minu >> r >> pl >> t;
    if (t == 'r') {
      if (r == 'a') {
        if (playersa[pl] != 2) {
          cout << away << " " << pl << " " << minu << endl;
          playersa[pl] = 2;
        };
      } else {
        if (playersh[pl] != 2) {
          cout << home << " " << pl << " " << minu << endl;
          playersh[pl] = 2;
        };
      }
    } else {
      if (r == 'a') {
        if (playersa[pl] == 1) {
          cout << away << " " << pl << " " << minu << endl;
          playersa[pl] = 2;
        } else {
          if (playersa[pl] == 0) {
            playersa[pl] = 1;
          };
        }
      } else {
        if (playersh[pl] == 1) {
          cout << home << " " << pl << " " << minu << endl;
          playersh[pl] = 2;
        } else {
          if (playersh[pl] != 2) {
            playersh[pl] = 1;
          };
        };
      }
    }
  }
}
