for(a=[l=0];$=readline();++l%3||print(["35 69702418"[k%59%12]for([,k]in a)].join(a=[])))for([i,c]in $)a[i/3|0]|=c+2<