#include <bits/stdc++.h>
using namespace std;
using namespace placeholders;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using SS = stringstream;
using PII = pair<int, int>;
using VPII = vector<PII>;
template <typename T = int>
using VT = vector<T>;
template <typename T = int>
using VVT = VT<VT<T> >;
template <typename T = int>
using LIM = numeric_limits<T>;
template <typename T>
inline istream &operator>>(istream &s, vector<T> &v) {
  for (auto &t : v) {
    s >> t;
  }
  return s;
}
template <typename T>
inline ostream &operator<<(ostream &s, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    s << (" " + !i) << v[i];
  }
  return s;
}
template <typename T>
inline T fromString(const string &s) {
  T res;
  istringstream iss(s);
  iss >> res;
  return res;
};
template <typename T>
inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  VS teams(2);
  cin >> teams;
  int n;
  cin >> n;
  VVI counts(2, VI(100));
  for (int i = (int)(0); i < (int)(n); ++i) {
    int t, m;
    string team, card;
    cin >> t >> team >> m >> card;
    int &target = counts[team == "a"][m];
    if (card == "y") {
      ++target;
      if (target == 2) {
        cout << teams[team == "a"] << ' ' << m << ' ' << t << endl;
      }
    } else {
      if (target < 2) {
        cout << teams[team == "a"] << ' ' << m << ' ' << t << endl;
        target = 2;
      }
    }
  }
  return 0;
}
