First, how fortunate that the teacher only has 12 students!
12 does not go evenly into 40 or 56. Recall:
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
However, if you add 40+56 you get 96 writing utensils altogether. Fortunately, 96 is divisible by 12:
12 x 8 = 96
So, each of the 12 students will get 8 writing utensils. Some will get 3 pens and 5 pencils; and others will get 4 of each (bonus points for figuring out how many!).