#include <bits/stdc++.h>
bool got[201];
int yc[201];
int main() {
  std::string hname;
  std::cin >> hname;
  std::string aname;
  std::cin >> aname;
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    std::cin >> t;
    std::string o;
    std::cin >> o;
    int m;
    std::cin >> m;
    std::string c;
    std::cin >> c;
    int in = m + (o[0] == 'a' ? 100 : 0);
    if (got[in]) continue;
    if (c[0] == 'r') {
      std::cout << (o[0] == 'a' ? aname : hname) << ' ' << m << ' ' << t
                << '\n';
      got[in] = true;
    } else {
      yc[in]++;
      if (yc[in] == 2) {
        std::cout << (o[0] == 'a' ? aname : hname) << ' ' << m << ' ' << t
                  << '\n';
        got[in] = true;
      }
    }
  }
  return 0;
}
