#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>

#define FOR(a, b) for(int (a) = 0; (a) < (b); (a)++)

using namespace std;

struct UserInfo{
	string name;
	int maxStreak;
	int usedFreeze;
	int startMax;
	int failedCount;
};

bool compare(UserInfo a, UserInfo b){
	if (a.maxStreak == b.maxStreak){
		if(a.usedFreeze == b.usedFreeze){
			if(a.startMax == b.startMax){
				if(a.failedCount == b.failedCount) return a.name < b.name;
				else return a.failedCount < b.failedCount;
			}
			else return a.startMax < b.startMax;
		}
		else return a.usedFreeze < b.usedFreeze;
	}
	return a.maxStreak > b.maxStreak;
	
}


int N, W;

vector<UserInfo> users;
vector<string> pan;


int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> N >> W;
	
	FOR(testcase, N){
		string nme; cin >> nme;
		UserInfo usi = {nme, 0, 0, 0, 0};
		pan.clear();
		
		FOR(week, 7){
			string pannel; cin >> pannel;
			pan.push_back(pannel);
		}
		
		
		int count = 0;
		int streak = 0;
		int frezeinst = 0;
		int date = 0;
		
		FOR(x, W) FOR(y, 7){
			
			//스트릭 날짜 기록용
			if (streak == 0) date = count;
			count++;
			
			// 스트릭 성공 케이스 처리
			if (pan[y][x] == 'O') streak++;
			// 스트릭 프리즈 사용 처리
			else if (pan[y][x] == 'F') frezeinst++;
			// 스트릭 실패
			else{
				usi.failedCount++;
				if(streak > usi.maxStreak){
					usi = {nme, streak, date, frezeinst, usi.failedCount};
				}
				else if (streak == usi.maxStreak && frezeinst < usi.usedFreeze){
					usi = {nme, streak, date, frezeinst, usi.failedCount};
				}
				streak = 0;
				frezeinst = 0;
				date = count;
				continue;
			}
		}
		
		if(streak > usi.maxStreak){
			usi = {nme, streak, date, frezeinst, usi.failedCount};
		}
		else if (streak == usi.maxStreak && frezeinst < usi.usedFreeze){
			usi = {nme, streak, date, frezeinst, usi.failedCount};
		}
		users.push_back(usi);
	}
	
	sort(users.begin(), users.end(), compare);
	
	int ct = 0;
	
	UserInfo last;
	
	FOR(i, users.size()){
		
		
		if (i > 0){
			if(last.maxStreak != users[i].maxStreak || last.usedFreeze != users[i].usedFreeze || last.startMax != users[i].startMax || last.failedCount != users[i].failedCount) ct = i + 1;
		}
		else ct = i + 1;
		cout << ct << ". " << users[i].name << "\n";
		last = users[i];
		//cout << users[i].maxStreak << " " << users[i].usedFreeze << " " << users[i].startMax << " " << users[i].failedCount << "\n";
	}
	
	return 0;
}