n=eval(input())

for _ in [0]*n:

  i=0

  b=0

  c=0

  while i<3:

    s=input()[1]

    if s=='I':

      if b==3:c+=1

      else: b+=1

    elif s=='O':

      c+=b+1

      b=0

    elif s=='U':i+=1

  print(c)
n=eval(input())

for _ in [0]*n:

  i,b,c=0,0,0

  while i<3:

    s="IOU".index(input()[1])

    if s==0:

      if b==3: c+=1

      else: b+=1

    elif s==1:

      c+=b+1

      b=0

    elif s==2: i+=1

  print(c)
n = eval(input())
for _ in [0] * n:
    i = 0
    b = 0
    c = 0
    while i < 3:
        s = input()[1]
        if s == "I":
            if b == 3:
                c += 1
            else:
                b += 1
        elif s == "O":
            c += b + 1
            b = 0
        elif s == "U":
            i += 1
    print(c)

n = eval(input())
for _ in [0] * n:
    i, b, c = 0, 0, 0
    while i < 3:
        s = "IOU".index(input()[1])
        if s == 0:
            if b == 3:
                c += 1
            else:
                b += 1
        elif s == 1:
            c += b + 1
            b = 0
        elif s == 2:
            i += 1
    print(c)

-    i = 0 -    b = 0 -    c = 0 +    i, b, c = 0, 0, 0 -        s = input()[1] -        if s == "I": +        s = "IOU".index(input()[1]) +        if s == 0: -        elif s == "O": +        elif s == 1: -        elif s == "U": +        elif s == 2: