#include <iostream>
#include <algorithm>
#include<string>
#include<vector>
int main() {
	int ining;
	std::cin >> ining;
	std::string s;
	for (int i = 0; i < ining; ++i) {
		int co = 0;
		int ch = 0;
		int c = 0;
		while (std::cin >> s) {
			if (s == "OUT") {
				++co;
			}
			if (co == 3) {
				break;
			}
			if (s == "HIT") {
				++ch;
			}
			if (ch == 4) {
				--ch;
				++c;
			}
			if (s == "HOMERUN") {
				c += ch + 1;
				ch = 0;
			}
		}
		std::cout << c << std::endl;
	}
	}
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n+1);
		rep(i,n)cin>>in[i+1];
		n++;
		loop(i,1,n)in[i]+=in[i-1];
		int ma=-1e9;
		rep(i,n)loop(j,i+1,n)ma=max(ma,in[j]-in[i]);
		cout<<ma<<endl;
	}
}