#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int n;
  cin >> n;
  map<int, char> A;
  map<int, char> H;
  while (n--) {
    int t, num;
    char code, bhasin_kutiya;
    cin >> t >> code >> num >> bhasin_kutiya;
    if (code == 'a') {
      if ((bhasin_kutiya == 'r' || A[num] == 'y') && A[num] != 'r') {
        cout << b << " " << num << " " << t << endl;
        A[num] = 'r';
      } else if (A[num] != 'r') {
        A[num] = 'y';
      }
    } else {
      if ((bhasin_kutiya == 'r' || H[num] == 'y') && H[num] != 'r') {
        cout << a << " " << num << " " << t << endl;
        H[num] = 'r';
      } else if (H[num] != 'r') {
        H[num] = 'y';
      }
    }
  }
  return 0;
}
