Micro's school puts a limit on the maximum number of students that can be enrolled in any course. As the new session is starting all the students have filled their preferences. Now since Micro is very busy, he needs your help. He'll give you details about the courses, their limits and about all the students and their rank in the previous session and about their preferences. Course allotment is done on the basis of student's preference, their respective rank and the limit of the course. Check sample for more clarity. Now help Micro generate the list of course allotment. For better understanding of the problem, refer to the sample explanation given below.
These are three tables that you have to use. The schema of the tables is as given below.
Table : Students
Sample Students table:
Sample Courses table:
Sample Preferences table:
$$4$$ students added $$Science$$ as preference but it's limit is $$2$$, so the first $$2$$ students (according to rank), will get the course.
Only $$1$$ student preferred $$Math$$, and it's limit is $$3$$, so he'll get it.