calculates price of newspaper

input 1: # of newspapers
input 2 (do rest for every newspaper): set of character/prices separated by space
input 3: how many lines of text
input 4: newspaper text


The price of the newspaper will be calculated and outputted.