Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.

Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.

Input

The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.

Next follows number n (1 ≤ n ≤ 90) — the number of fouls. 

Each of the following n lines contains information about a foul in the following form: 

  * first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; 
  * then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; 
  * then goes the player's number m (1 ≤ m ≤ 99); 
  * then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. 



The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.

Output

For each event when a player received his first red card in a chronological order print a string containing the following information:

  * The name of the team to which the player belongs; 
  * the player's number in his team; 
  * the minute when he received the card. 



If no player received a card, then you do not need to print anything.

It is possible case that the program will not print anything to the output (if there were no red cards).

Examples

Input

MC
CSKA
9
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 r


Output

MC 25 70
MC 42 82
CSKA 13 90

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class C493A {
    enum Card {YELLOW, RED};

    public static class Init {
        public SoccerTeam houses;
        public SoccerTeam guest;

        public Init() throws IOException {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String[] items;

            houses = new SoccerTeam(reader.readLine());
            guest = new SoccerTeam(reader.readLine());

            int n = Integer.parseInt(reader.readLine());

            int minute;
            char type;
            int playerNumber;
            Card card;

            for (int index = 0; index < n; index++) {
                items = reader.readLine().split(" ");

                minute = Integer.parseInt(items[0]);
                type = (items[1].charAt(0) == 'a') ? 'a' : 'h';
                playerNumber = Integer.parseInt(items[2]);
                card = (items[3].charAt(0) == 'y') ? Card.YELLOW : Card.RED;

                switch (type) {
                    case 'a':
                        guest.addFoul(playerNumber, new Foul(minute, card));
                        break;

                    case 'h':
                        houses.addFoul(playerNumber, new Foul(minute, card));
                        break;
                }

            }
            reader.close();
        }
    }

    public static class SoccerTeam {
        public String name;
        public Map<Integer, FootballPlayer> players = new LinkedHashMap<Integer, FootballPlayer>();

        public SoccerTeam(String name) {
            this.name = name;
        }

        public void addFoul(int numberPlayer, Foul foul) {
            if (!players.containsKey(numberPlayer)) {
                players.put(numberPlayer, new FootballPlayer(numberPlayer));
            }
            players.get(numberPlayer).addFoul(foul);
        }

        public Map<Integer, String> playersRedCard() {
            TreeMap<Integer, String> answer = new TreeMap<Integer, String>();

            Set<Integer> keys = players.keySet();
            for (Integer key: keys) {

                FootballPlayer player = players.get(key);

                int redCard = 0;
                int yellowCard = 0;

                for(Foul foul: player.fouls) {
                   if (foul.card == Card.RED) {
                       redCard += 1;
                   } else if (foul.card == Card.YELLOW) {
                       yellowCard += 1;
                   }

                   if (redCard >= 1 || yellowCard >= 2) {
                       answer.put(foul.minute, name + " " + player.number + " " + foul.minute);
                       break;
                   }
                }

            }
            return answer;
        }

        @Override
        public boolean equals(Object obj) {
            SoccerTeam team = (SoccerTeam) obj;
            boolean result = false;

            if (name.equals(team.name) && players.size() == team.players.size()) {

                Set<Integer> keys = players.keySet();
                for (Integer key: keys) {

                    result = false;
                    if (players.containsKey(key) && team.players.containsKey(key)) {
                        if (players.get(key).equals(team.players.get(key))) {
                            result = true;
                        }
                    }

                    if (result == false) {
                        break;
                    }
                }
            }
            return result;
        }
    }

    public static class FootballPlayer {
        public int number;
        public List<Foul> fouls = new LinkedList<Foul>();

        public FootballPlayer(int number) {
            this.number = number;
        }

        public void addFoul(Foul foul) {
            fouls.add(foul);
        }

        @Override
        public boolean equals(Object obj) {
            FootballPlayer player = (FootballPlayer) obj;
            boolean result = false;

            if (number == player.number && fouls.size() == player.fouls.size()) {
                result = true;

                Iterator<Foul> iterH = fouls.iterator();
                Iterator<Foul> iterA = player.fouls.iterator();

                while (iterH.hasNext() && iterA.hasNext()) {
                    if (!iterH.next().equals(iterA.next())) {
                        result = false;
                        break;
                    }
                }
            }
            return result;
        }
    }

    public static class Foul {
        public int minute;
        public Card card;

        public Foul(int minute, Card card) {
            this.minute = minute;
            this.card = card;
        }

        @Override
        public boolean equals(Object obj) {
            Foul foul = (Foul) obj;

            if (minute == foul.minute && card == foul.card) {
                return true;
            }
            return false;
        }
    }

    interface Answer {
        void print();
    }

    interface Printable {
        Answer answer();
    }

    public static class Algorithm implements Printable {
        private SoccerTeam houses;
        private SoccerTeam guest;
        private Map<Integer, String> answer = new TreeMap<Integer, String>();

        public Algorithm(SoccerTeam houses, SoccerTeam guest) {
            this.houses = houses;
            this.guest = guest;
        }

        public void run() {
            answer.clear();

            answer.putAll(houses.playersRedCard());
            answer.putAll(guest.playersRedCard());
        }

        private class A implements Answer {
            @Override
            public void print() {
                Set<Integer> keys = answer.keySet();
                for (Integer key: keys) {
                    System.out.println(answer.get(key));
                }
            }
        }

        @Override
        public Answer answer() {
            return new A();
        }
    }

    public static void main(String[] args) throws IOException {
        Init init = new Init();
        Algorithm algorithm = new Algorithm(init.houses, init.guest);
        algorithm.run();
        algorithm.answer().print();
    }
}
