#include <bits/stdc++.h>
using namespace std;
struct kart {
  int t, m, k;
  string c;
};
bool cmp(kart a, kart b) { return a.t < b.t; }
int main() {
  long n, m, i, tt, c;
  long kk[2][100];
  bool ud[2][100];
  for (i = 0; i < 100; i++) {
    ud[0][i] = ud[1][i] = false;
    kk[0][i] = kk[1][i] = 0;
  }
  string h, a, q, k;
  cin >> h >> a;
  cin >> n;
  vector<kart> ka(n);
  for (i = 0; i < n; i++) {
    cin >> tt >> q >> m >> k;
    ka[i].t = tt;
    if (q == "h")
      ka[i].c = h;
    else
      ka[i].c = a;
    ka[i].m = m;
    if (k == "y")
      ka[i].k = 1;
    else
      ka[i].k = 2;
  }
  sort(ka.begin(), ka.end(), cmp);
  for (i = 0; i < n; i++) {
    if (ka[i].c == h)
      c = 0;
    else
      c = 1;
    if (!ud[c][ka[i].m] && ka[i].k == 2) {
      cout << ka[i].c << " " << ka[i].m << " " << ka[i].t << "\n";
      ud[c][ka[i].m] = true;
    } else if (!ud[c][ka[i].m]) {
      kk[c][ka[i].m]++;
      if (kk[c][ka[i].m] == 2) {
        cout << ka[i].c << " " << ka[i].m << " " << ka[i].t << "\n";
        ud[c][ka[i].m] = true;
      }
    }
  }
  return 0;
}
