Pablo wants to go abroad to study and he is reciting GRE words. However, Pablo finds it hard to recite all the words in such a thick book just in one time. He decides to divide the words into groups and recite(according to the appearance frequency of each word in the past exams, the words in the same group have the same frequency).
Now Pablo comes to ask your help again, but he doesn??t want you to finish the job easily this time. Pablo gives all the GRE words to you and adds some word pairs (two different words become a pair which means the two words have the same appearance frequency in the past exams).
You are asked to tell him the number of the groups and the number of the words of the group which contains the most words.
The input file contains several input sets. The description of each set is given below:
Each set starts with lines giving all the words, each consisting of lower case letters (a, b,??,z). Words will be terminated by a line containing '-'. No word is longer than 10 letters. Then there will be lines describing the relations. Each line will have 2 words, meaning that the two words have the same appearance frequency in the past exams. Words relations will be terminated by a line containing ??- -??. You may assume that the number of words and the number of relations will less than 5000.
For each test case, print a single line containing two integers: the number of groups and the max size of group, separated by a space.