import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    private static class Student {
        private final String id;
        private final int score;
        private Student(String id, int score) {
            this.id = id;
            this.score = score;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            if (N == 0) break;
            int M = sc.nextInt();
            int G = sc.nextInt();
            int[] scores = new int[M + 1];
            for (int i = 1; i <= M; i++) {
                scores[i] = sc.nextInt();
            }
            List<Student> students = new ArrayList<>();
            while (N-- != 0) {
                String id = sc.next();
                int m = sc.nextInt();
                int sum = 0;
                while (m-- != 0) {
                    int index = sc.nextInt();
                    sum += scores[index];
                }
                if (sum >= G) students.add(new Student(id, sum));
            }
            System.out.println(students.size());
            students.stream().sorted((o1,
                                      o2) -> o1.score == o2.score ? o1.id.compareTo(o2.id) : o2.score -
                                     o1.score).forEach(student -> System.out.println(student.id + " " +
                                             student.score));
        }
    }
}