        implicit real*8(a-h, o-z)
        dimension ngaku(100),nsaiten(100),
     &  sinki(100,20),sinrai(100,20),happyou(100,20),situmon(100,20)
        character(10) saiten(100,20),
     &  asinki,asinrai,ahappyou,asitumon
!
        read*, ninzuu
        do i=1,ninzuu
         read*, ngaku(i)
         read*, nsaiten(i)
         do j=1,nsaiten(i)
         read*,saiten(i,j),
     &   asinki,asinrai,ahappyou,asitumon
         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
!
         print*, ngaku(i), ',' , saiten(i,j), ',' ,
     &   gsinki/nsinki, ',' ,
     &   gsinrai/nsinrai, ',' ,
     &   ghappyou/nhappyou, ',' ,
     &   gsitumon/nsitumon
        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
!
