import com.sun.source.tree.Tree;

import java.util.Scanner;
import java.util.TreeSet;

public class Digitalisation {


    static Student[] students;
    static TreeSet<Integer>[] schools;
    static TreeSet<Integer> availableStudents;
    static int schoolCapacity;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int numOfStudents = sc.nextInt();
        int numOfSchools = sc.nextInt();
        schoolCapacity = sc.nextInt();

        students = new Student[numOfStudents];
        schools = new TreeSet[numOfSchools];
        availableStudents = new TreeSet<>();

        for (int i = 0; i < numOfSchools; i++) {
            schools[i] = new TreeSet<>();
        }

        for (int i = numOfStudents - 1; i >= 0; i--) {
            students[i] = new Student(i, sc.nextInt() - 1, sc.nextInt() - 1);
            availableStudents.add(i);
        }

        boolean update = true;
        while (update) {
            update = false;
            for (int i = 0; i < numOfSchools; i++) {
                update = updateEvent(i);
            }
        }

        int primary = 0;
        int secondary = 0;
        for (int i = 0; i < numOfSchools; i++) {
            for (Integer studentIndex : schools[i]) {
                Student student = students[studentIndex];
                if (student.prior == i)
                    primary++;
                else if (student.second == i)
                    secondary++;
                else
                    System.out.println("problem");
            }
        }

        System.out.println(primary + " " + secondary);
    }

    public static boolean updateEvent(int schoolIndex) {
        for (int studentIndex : availableStudents) {
            Student student = students[studentIndex];
            if (conditions(student, schoolIndex)) {
                schools[schoolIndex].add(student.index);

                if (schools[schoolIndex].size() > schoolCapacity) {
                    Student removedStudent = students[schools[schoolIndex].last()];
                    schools[schoolIndex].remove(removedStudent.index);
                    removedStudent.assigned = false;

                    if (removedStudent.prior == schoolIndex) {
                        availableStudents.add(removedStudent.index);
                    }
                }

                if (student.assigned) {
                    schools[student.second].remove(student.index);
                }

                if (student.prior == schoolIndex) {
                    availableStudents.remove(student.index);
                }
                student.assigned = true;
                return true;
            }
        }
        return false;
    }

    public static boolean conditions(Student student, int schoolIndex) {
        if (!(schools[schoolIndex].size() < schoolCapacity || student.index > schools[schoolIndex].last())) {
            return false;
        }

        if (!(student.prior == schoolIndex || student.second == schoolIndex)) {
            return false;
        }

        return (!student.assigned || schoolIndex == student.prior);
    }

    public static class Student {
        public int index;
        public int prior;
        public int second;
        public boolean assigned;

        public Student(int index, int prior, int second) {
            this.index = index;
            this.prior = prior;
            this.second = second;
            this.assigned = false;
        }
    }
}
