Upon examining the contents of 38 backpacks, it was found that 23 contained a black pen, 27 contained a blue pen, and 21 contained a pencil, 15 contained both a black pen and a blue pen, 12 contained both a black pen and a pencil, 18 contained both a blue pen and a pencil, and 10 contained all three items. How many backpacks contained exactly two of the three writing instruments?