#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 5;
int main() {
  string s, t;
  cin >> s >> t;
  vector<int> h(MAXN, 0);
  vector<int> a(MAXN, 0);
  int n = 0, m = 0, b = 0;
  cin >> n;
  string k, e;
  for (int i = 0; i < n; ++i) {
    cin >> b >> k >> m >> e;
    if (k == "h") {
      if (h[m] == -1) {
        continue;
      }
      if (h[m] == 0) {
        if (e == "r") {
          h[m] = -1;
          cout << s << " " << m << " " << b << endl;
          continue;
        } else {
          h[m] = 1;
        }
      } else {
        cout << s << " " << m << " " << b << endl;
        h[m] = -1;
      }
    } else {
      if (a[m] == -1) {
        continue;
      }
      if (a[m] == 0) {
        if (e == "r") {
          a[m] = -1;
          cout << t << " " << m << " " << b << endl;
          continue;
        } else {
          a[m] = 1;
        }
      } else {
        cout << t << " " << m << " " << b << endl;
        a[m] = -1;
      }
    }
  }
  return 0;
}
