Problem: Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).

Each item belongs to one class. In this problem we will only consider three of such classes: weapon, armor, orb.

Besides, there's a whole new world hidden inside each item. We can increase an item's level travelling to its world. We can also capture the so-called residents in the Item World

Residents are the creatures that live inside items. Each resident gives some bonus to the item in which it is currently located. We will only consider residents of types: gladiator (who improves the item's atk), sentry (who improves def) and physician (who improves res).

Each item has the size parameter. The parameter limits the maximum number of residents that can live inside an item. We can move residents between items. Within one moment of time we can take some resident from an item and move it to some other item if it has a free place for a new resident. We cannot remove a resident from the items and leave outside — any of them should be inside of some item at any moment of time.

Laharl has a certain number of items. He wants to move the residents between items so as to equip himself with weapon, armor and a defensive orb. The weapon's atk should be largest possible in the end. Among all equipping patterns containing weapon's maximum atk parameter we should choose the ones where the armor’s def parameter is the largest possible. Among all such equipment patterns we should choose the one where the defensive orb would have the largest possible res parameter. Values of the parameters def and res of weapon, atk and res of armor and atk and def of orb are indifferent for Laharl.

Find the optimal equipment pattern Laharl can get.

Input

The first line contains number n (3 ≤ n ≤ 100) — representing how many items Laharl has.

Then follow n lines. Each line contains description of an item. The description has the following form: "name class atk def res size" — the item's name, class, basic attack, defense and resistance parameters and its size correspondingly. 

  * name and class are strings and atk, def, res and size are integers. 
  * name consists of lowercase Latin letters and its length can range from 1 to 10, inclusive. 
  * class can be "weapon", "armor" or "orb". 
  * 0 ≤ atk, def, res ≤ 1000. 
  * 1 ≤ size ≤ 10. 



It is guaranteed that Laharl has at least one item of each class.

The next line contains an integer k (1 ≤ k ≤ 1000) — the number of residents.

Then k lines follow. Each of them describes a resident. A resident description looks like: "name type bonus home" — the resident's name, his type, the number of points the resident adds to the item's corresponding parameter and the name of the item which currently contains the resident. 

  * name, type and home are strings and bonus is an integer. 
  * name consists of lowercase Latin letters and its length can range from 1 to 10, inclusive. 
  * type may be "gladiator", "sentry" or "physician". 
  * 1 ≤ bonus ≤ 100. 



It is guaranteed that the number of residents in each item does not exceed the item's size.

The names of all items and residents are pairwise different.

All words and numbers in the input are separated by single spaces.

Output

Print on the first line the name of the weapon in the optimal equipping pattern; then print the number of residents the weapon contains; then print the residents' names.

Print on the second and third lines in the same form the names of the armor and defensive orb as well as the residents they contain. 

Use single spaces for separation.

If there are several possible solutions, print any of them.

Examples

Input

4
sword weapon 10 2 3 2
pagstarmor armor 0 15 3 1
iceorb orb 3 2 13 2
longbow weapon 9 1 2 1
5
mike gladiator 5 longbow
bobby sentry 6 pagstarmor
petr gladiator 7 iceorb
teddy physician 6 sword
blackjack sentry 8 sword


Output

sword 2 petr mike 
pagstarmor 1 blackjack 
iceorb 2 teddy bobby 


Input

4
sword weapon 10 2 3 2
pagstarmor armor 0 15 3 1
iceorb orb 3 2 13 2
longbow weapon 9 1 2 1
6
mike gladiator 5 longbow
bobby sentry 6 pagstarmor
petr gladiator 7 iceorb
teddy physician 6 sword
blackjack sentry 8 sword
joe physician 6 iceorb


Output

longbow 1 mike 
pagstarmor 1 bobby 
iceorb 2 petr joe 

Note

In the second sample we have no free space inside the items, therefore we cannot move the residents between them.

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.math.*;
import static java.lang.Math.*;

public class Main{
    
    HashMap< String,Integer > ItemIDs = new HashMap< String,Integer >();
    HashMap< Integer,String > ItemIDsR = new HashMap< Integer,String >();
    HashMap< String,Integer > ResiIDs = new HashMap< String,Integer >();
    HashMap< Integer,String > ResiIDsR = new HashMap< Integer,String >();
    HashMap< String,Integer > fixedShit1 = new HashMap< String,Integer >();
    HashMap< String,Integer > fixedShit2 = new HashMap< String,Integer >();

    public void go(){
        runSetup();
        int n=sc.nextInt();
        ArrayList< object > Items = new ArrayList< object >();
        ArrayList< object > Weapons = new ArrayList< object >();
        ArrayList< object > Armors = new ArrayList< object >();
        ArrayList< object > Orbs = new ArrayList< object >();
        ArrayList< object > Residents = new ArrayList< object >();
        ArrayList< object > Gladiators = new ArrayList< object >();
        ArrayList< object > Sentrys = new ArrayList< object >();
        ArrayList< object > Physicians = new ArrayList< object >();

        int sumItemSzs=0;

        for(int i=0; i<n; ++i){
            String name=sc.nextToken(), clas=sc.nextToken();
            int[] stats = new int[3];
            for(int j=0; j<3; ++j) stats[j] = sc.nextInt();
            int sz=sc.nextInt(); sumItemSzs += sz;
            ItemIDs.put(name, i);
            ItemIDsR.put(i, name);
            Items.add(new object(i, -1, stats[fixedShit1.get(clas)], sz, fixedShit1.get(clas)));
            if(fixedShit1.get(clas)==0)
                Weapons.add(Items.get(Items.size()-1));
            else if(fixedShit1.get(clas)==1)
                Armors.add(Items.get(Items.size()-1));
            else
                Orbs.add(Items.get(Items.size()-1));
        }

        int m=sc.nextInt();
        for(int i=0; i<m; ++i){
            String name=sc.nextToken(), type=sc.nextToken();
            int bonus=sc.nextInt(), parent=ItemIDs.get(sc.nextToken());
            ResiIDs.put(name, i);
            ResiIDsR.put(i, name);
            Residents.add(new object(i, parent, bonus, 0, fixedShit1.get(type)));
            if(fixedShit1.get(type)==0)
                Gladiators.add(Residents.get(Residents.size()-1));
            else if(fixedShit1.get(type)==1)
                Sentrys.add(Residents.get(Residents.size()-1));
            else
                Physicians.add(Residents.get(Residents.size()-1));
        }

        // stuck with what we got
        if(sumItemSzs == m){
            for(object o : Residents) Items.get(o.pid).residents.add(o.id);
            for(object o : Items)
                for(int oo : o.residents)
                    if(Residents.get(oo).type == o.type)
                        o.stat += Residents.get(oo).stat;
            int bestw=-1, bestwid=-1, besta=-1, bestaid=-1, besto=-1, bestoid=-1;
            for(object o : Weapons) if(o.stat > bestw){
                bestw = o.stat;
                bestwid = o.id;
            }
            for(object o : Armors) if(o.stat > besta){
                besta = o.stat;
                bestaid = o.id;
            }
            for(object o : Orbs) if(o.stat > besto){
                besto = o.stat;
                bestoid = o.id;
            }

            System.out.printf("%s %d", ItemIDsR.get(Items.get(bestwid).id), Items.get(bestwid).residents.size());
            for(int i : Items.get(bestwid).residents)
                System.out.printf(" %s", ResiIDsR.get(i));
            System.out.printf("\n");

            System.out.printf("%s %d", ItemIDsR.get(Items.get(bestaid).id), Items.get(bestaid).residents.size());
            for(int i : Items.get(bestaid).residents)
                System.out.printf(" %s", ResiIDsR.get(i));
            System.out.printf("\n");

            System.out.printf("%s %d", ItemIDsR.get(Items.get(bestoid).id), Items.get(bestoid).residents.size());
            for(int i : Items.get(bestoid).residents)
                System.out.printf(" %s", ResiIDsR.get(i));
            System.out.printf("\n");

        }else{
    
            // greedy on residents
            Collections.sort(Gladiators);
            Collections.sort(Sentrys);
            Collections.sort(Physicians);

            // find best of each
            object[] bestGear = new object[3];
            for(object item : Items){
                ArrayList< object > meShit = item.type==0 ? Gladiators : item.type==1 ? Sentrys : Physicians;
                for(int i=0; i<min(item.sz, meShit.size()); ++i){
                    item.residents.add(meShit.get(i).id);
                    item.stat += meShit.get(i).stat;
                }
                if(bestGear[item.type]==null || item.stat > bestGear[item.type].stat)
                    bestGear[item.type] = item;
            }

            ArrayList< ArrayList< object > > allgear = new ArrayList< ArrayList< object > >();
            allgear.add(Gladiators);
            allgear.add(Sentrys);
            allgear.add(Physicians);

            // fill out with residents, this handles when it is necessary
            int[] used = new int[3], exists = new int[3];
            for(int i=0; i<3; ++i) used[i] = bestGear[i].residents.size();
            exists[0] = Gladiators.size();
            exists[1] = Sentrys.size();
            exists[2] = Physicians.size();
            for(int i=0; i<3; ++i){
                for(int j=0; j<3; ++j) while(used[j] < exists[j] && bestGear[i].residents.size() < bestGear[i].sz){
                    bestGear[i].residents.add(allgear.get(j).get(used[j]).id);
                    ++used[j];
                }
            }

            for(int i=0; i<3; ++i){
                System.out.printf("%s %d", ItemIDsR.get(bestGear[i].id), bestGear[i].residents.size());
                for(int j : bestGear[i].residents)
                    System.out.printf(" %s", ResiIDsR.get(j));
                System.out.printf("\n");
            }

        }

    }

    public class object implements Comparable< object >{
        int id, pid, stat, sz, type;
        ArrayList< Integer > residents = new ArrayList< Integer >();
        public object(int _id, int _pid, int _stat, int _sz, int _type){
            id=_id; pid=_pid; stat=_stat; sz=_sz; type=_type;
        }
        public int compareTo(object o){ return o.stat-stat; }
    }

    public void runSetup(){
        fixedShit1.put("weapon", 0);
        fixedShit1.put("armor", 1);
        fixedShit1.put("orb", 2);
        fixedShit1.put("gladiator", 0);
        fixedShit1.put("sentry", 1);
        fixedShit1.put("physician", 2);
        fixedShit2.put("weapon", 0);
        fixedShit2.put("armor", 0);
        fixedShit2.put("orb", 0);
        fixedShit2.put("gladiator", 1);
        fixedShit2.put("sentry", 1);
        fixedShit2.put("physician", 1);
    }

    // syntax
    // ArrayList<Integer>[] myMat = (ArrayList<Integer>[]) new ArrayList[nB];

    // Pairs
    public class ii implements Comparable< ii >{
        int x, y;
        public ii(){}
        public ii(int xx, int yy){ x=xx; y=yy; }
        public int compareTo(ii p){ return x!=p.x ? x-p.x : y-p.y; }
        public int hashCode(){ return 31*x+y; }
        public boolean equals(Object o){
            if(!(o instanceof ii)) return false;
            ii p = (ii) o;
            return x==p.x && y==p.y;
        }
        public String toString(){ return "("+x+", "+y+")"; }
    }
/*
    public class pair< X extends Comparable< X >,Y extends Comparable< Y > > implements Comparable< pair< X,Y > >{
        X x;
        Y y;
        public pair(){}
        public pair(X xx, Y yy){ x=xx; y=yy; }
        public int compareTo(pair< X,Y > p){ return x.compareTo(p.x)!=0 ? x.compareTo(p.x) : y.compareTo(p.y); }
        public int hashCode(){ return 31*x.hashCode()+y.hashCode(); }
        public boolean equals(Object o){
            if((o.getClass() != this.getClass())) return false;
            pair< X,Y > p = (pair< X,Y >) o;
            return x.equals(p.x) && y.equals(p.y);
        }
        public String toString(){ return "("+x+", "+y+")"; }
    }
*/
    // my stuff
    public static final int INF = 1000*1000*1000+7;
    public static final double EPS = 1e-9;
    public static final double PI = 2*acos(0.0);
    public void rev(Object[] a){ for(int i=0; i<a.length/2; ++i){ Object t=a[i]; a[i]=a[a.length-1-i]; a[a.length-1-i]=t; } }
    public void rev(int[] a){ for(int i=0; i<a.length/2; ++i){ int t=a[i]; a[i]=a[a.length-1-i]; a[a.length-1-i]=t; } }
    public int bit_count(long x){ return x==0 ? 0 : 1+bit_count(x&(x-1)); }
    public int low_bit(int x){ return x&-x; } // 0011 0100 returns 0000 0100
    public int sign(int x){ return x<0 ? -1 : x>0 ? 1 : 0; }
    public int sign(double x){ return x<-EPS ? -1 : x>EPS ? 1 : 0; }
    int[] unpack(ArrayList< Integer > a){
        int[] ret = new int[a.size()];
        for(int i=0; i<a.size(); ++i) ret[i] = a.get(i);
        return ret;
    }

    // generic main stuff
    static myScanner sc;
    static PrintWriter pw;
    static long startTime;
    public static void main(String[] args) throws Exception{
        // sc = new Scanner(System.in);
        sc = (new Main()).new myScanner(new BufferedReader(new InputStreamReader(System.in)));
        pw = new PrintWriter(System.out);
        startTime = System.nanoTime();
        (new Main()).go();
        // errprintln("nanoTime="+(System.nanoTime()-startTime)/1000000/1000.0);
        pw.flush();
        System.exit(0);
    }

    // capable of reading   2.86M 6dp doubles per second
    //                      2.16M 12dp doubles per second
    //                      2.75M int per second
    public class myScanner{
        private BufferedReader f;
        private StringTokenizer st;
        public myScanner(BufferedReader ff){ f=ff; st=new StringTokenizer(""); }
        public int nextInt(){ return Integer.parseInt(nextToken()); }
        public double nextDouble(){ return Double.parseDouble(nextToken()); }
        public String nextLine(){
            st=new StringTokenizer("");
            String ret="";
            try{ ret=f.readLine(); }catch(Exception e){}
            return ret;
        }
        public String nextToken(){
            while(!st.hasMoreTokens()) try{ st=new StringTokenizer(f.readLine()); } catch(Exception e){}
            return st.nextToken();
        }
    }


}