        implicit real*8(a-h, o-z)
        dimension nsaiten(100),
     &  sinki(100,20),sinrai(100,20),happyou(100,20),situmon(100,20)
        character(10) saiten(100,20),
     &  asinki,asinrai,ahappyou,asitumon
        character(50) a50(100)
        character(5) ngaku(100)
!
        read*, ninzuu
        do i=1,ninzuu
         read*, ngaku(i),a50(i)
         j=0
         do 
         j=j+1
         read*,saiten(i,j),
     &   asinki,asinrai,ahappyou,asitumon
         if(saiten(i,j)=='zzz') exit
         nsaiten(i)=j
         call abcd(asinki,sinki,i,j)
         call abcd(asinrai,sinrai,i,j)
         call abcd(ahappyou,happyou,i,j)
         call abcd(asitumon,situmon,i,j)
         end do
        end do
!
!
!
        do i=1,ninzuu
          gsinki=0.; gsinrai=0.; ghappyou=0.; gsitumon=0.
          nsinki=nsaiten(i);   nsinrai=nsaiten(i)
          nhappyou=nsaiten(i); nsitumon=nsaiten(i)
         do j=1,nsaiten(i)
!
         if(sinki(i,j)>8) then
           nsinki=nsinki-1
         else
          gsinki=gsinki+sinki(i,j)
         end if
!
         if(sinrai(i,j)>8) then
           nsinrai=nsinrai-1
         else
          gsinrai=gsinrai+sinrai(i,j)
         end if
!
         if(happyou(i,j)>8) then
           nhappyou=nhappyou-1
         else
          ghappyou=ghappyou+happyou(i,j)
         end if
!
         if(situmon(i,j)>8) then
          nsitumon=nsitumon-1
         else
          gsitumon=gsitumon+situmon(i,j)
         end if
!
         end do
!
         g1=gsinki/nsinki
         g2=gsinrai/nsinrai
         g3=ghappyou/nhappyou
         g4=gsitumon/nsitumon
         print'(a5,a,f5.1,a,f5.1,a,f5.1,a,f5.1,a,f10.3,a,a50)',
     &   ngaku(i),',',
     &   g1,',',g2,',',g3,',',g4,',',g1+g2+g3+g4,',',a50(i)
        end do
        end
!
!
!
!
!
        subroutine abcd(a,av,i,j)
        implicit real*8(a-h, o-z)
        dimension av(100,20)
        character(10) a
        if(a=='a') av(i,j)=4.
        if(a=='b') av(i,j)=3.
        if(a=='c') av(i,j)=2.
        if(a=='d') av(i,j)=1.
        if(a=='z') av(i,j)=9.
        return
        end
!
