import java.util.*;
import java.math.*;
public class Main{
static class Person {
private String name;
private int amount, received;
private String[] gifts;
public Person (String name, int amount, int received, String[] gifts){
this.name = name;
this.amount = amount;
this.gifts = gifts;
this.received = received;
}
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int n = sc.nextInt();
Person[] givers = new Person[n];
for(int i = 0; i < n; i++){
String s = sc.next();
givers[i] = new Person(s, 0, 0, null);
}
for(int i = 0; i < n; i++){
String name = sc.next();
for(int j = 0; j < n; j++){
if(givers[j].name.equals(name)){
int amount = sc.nextInt();
int num = sc.nextInt();
String[] gifts = new String[num];
for(int k = 0; k < num; k++){
gifts[k] = sc.next();
}
givers[j].amount = amount;
givers[j].gifts = gifts;
}
}
}
for(int i = 0; i < n; i++){
int len = givers[i].gifts.length;
int money = 0;
int given = givers[i].amount;
if(len != 0){
money = givers[i].amount/len;
}
for(int j = 0; j < len; j++){
for(int k = 0; k < n; k++){
if(givers[i].gifts[j].equals(givers[k].name)){
givers[i].amount -= money;
givers[k].received += money;
}
}
}
givers[i].amount = given - givers[i].amount;
}
for(int i = 0; i < n; i++){
System.out.println(givers[i].name + " " + (givers[i].received - givers[i].amount));
}
if(sc.hasNextInt()){
System.out.println();
}
}
}
}