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.util.*;
import java.lang.*;
import java.io.*;

public class R81B  {

    public static void main (String[] args) throws java.lang.Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        String t1 = in.next();
        String t2 = in.next();

        Player[] p1 = new Player[99];
        for (int i = 0; i < 99; i++)
            p1[i] = new Player(t1, i + 1, 0, 0, 0, false);

        Player[] p2 = new Player[99];
        for (int i = 0; i < 99; i++)
            p2[i] = new Player(t2, i + 1, 0, 0, 0, false);
        int n = in.nextInt();
        while (n-- > 0) {
            int tm = in.nextInt();
            String tmn = in.next();
            int pn = in.nextInt();
            String ct = in.next();
            if (tmn.equals("h")) {
                int yc = p1[pn - 1].yc;
                int rc = p1[pn - 1].rc;
                if (ct.equals("r"))
                    p1[pn - 1].rc += 1 ;
                else
                    p1[pn - 1].yc += 1;
                p1[pn-1].tm=tm;
                for (int i = 0; i < 99; i++) {
                    if ((p1[i].yc >= 2 || p1[i].rc >= 1) && !p1[i].done) {
                        w.println(p1[i].team + " " + p1[i].id + " " + p1[i].tm);
                        p1[i].done = true;
                    }
                }

            } else {
                int yc = p2[pn - 1].yc;
                int rc = p2[pn - 1].rc;
                if (ct.equals("r"))
                    p2[pn - 1].rc += 1;
                else
                    p2[pn - 1].yc += 1;
                p2[pn-1].tm=tm;
                for (int i = 0; i < 99; i++) {
                    if ((p2[i].yc >= 2 || p2[i].rc >= 1) && !p2[i].done) {
                        w.println(p2[i].team + " " + p2[i].id + " " + p2[i].tm);
                        p2[i].done = true;
                    }
                }
            }
        }
        w.close();
    }

    static class Player {

        String team;
        int id;
        int tm;
        int rc;
        int yc;
        boolean done;
        Player(String t, int i, int tm, int r, int y, boolean d) {
            this.team = t;
            this.id = i;
            this.tm = tm;
            this.rc = r;
            this.yc = y;
            this.done = d;
        }

    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1)
                return -1;
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0)
                read();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }
        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1)
                read();
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}