This is simply a case of ratio and proportion. By the Law of Definite Proportions, the ratio of the masses of hydrogen and nitrogen in any sample of ammonia must be the same.
We know that in a sample of ammonia, for every 9 grams of hydrogen, there are 42 grams of nitrogen, we can do the following calculation to determine amount of nitrogen in a sample of ammonia that contains 12 grams of hydrogen:
12 grams H x ( 42 grams N / 9 grams H) = 56 grams of nitrogen