public static void main(String... args) throws IOException {
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();
        Group[] g = new Group[n];
        for (int i = 0; i < n; i++) {
            g[i] = new Group(sc.nextInt(), sc.nextInt(), i + 1);
        }
        Arrays.sort(g, (a, b) -> b.m - a.m);

        int m = sc.nextInt();
        Pair[] t = new Pair[m];
        for (int i = 0; i < m; i++) {
            t[i] = new Pair(sc.nextInt(), i+1);
        }

        Arrays.sort(t, (a,b) -> a.v - b.v);

        int req = 0;
        int sum = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            Group g1 = g[i];
            int table = findTable(t, g1);
            if (table != -1) {
                while (table < t.length && t[table].v < 0) {
                    table++;
                }
                if (table < t.length) {
                    req++;
                    sum += g1.m;
                    t[table].v = -t[table].v;
                    sb.append(g1.n).append(' ').append(t[table].i).append('\n');
                }
            }
        }

        System.out.println(req + " " + sum);
        System.out.println(sb.toString());
    }