#include <iostream>
using namespace std;
int HitorOut(string str) {
if(str == "SO" || str == "FO" || str == "GO") {
return 0;
}
if(str == "1B") {
return 1;
}
if(str == "2B") {
return 2;
}
if(str == "3B") {
return 3;
}
if(str == "HR") {
return 4;
}
}
int main() {
int out1=0,out2=0,run=0,x,n,m;
//out1 總出局數
//out2 現在出局數
//run 得分
//x 題目要求出局數
int ab[9],base[9];
string c[9][5];
for(int i=0; i<9; i++) {
cin >> ab[i];
base[i] = 0;
for(int j=0; j<ab[i]; j++) {
cin >> c[i][j];
}
}
cin >> x;
n=0;//棒次-1
m=0;//第m-1個打席
while(out1<x) {
if(HitorOut(c[n][m]) == 0) {
out1++;
out2++;
}
else {
base[n]=HitorOut(c[n][m]);
for(int i=0; i<9; i++) {
if(i != n) {
if(base[i] != 0) {
base[i]+=HitorOut(c[n][m]);
}
}
if(base[i] >= 4) {
run++;
base[i] = 0;
}
}
}
if(out2 == 3) {
for(int i=0; i<8; i++) {
base[i] = 0;
}
out2 = 0;
}
if(n == 8) {
n = 0;
m++;
}
else {
n++;
}
}
cout << run;
cout << endl;
return 0;
}