#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

struct Player {
  int p, d;
  string name;
  Player () {
    p = d = 0;
  }
  bool operator< ( const Player& other ) const {
    return (p > other.p) || (p == other.p) && (d > other.d);
  }
};

int sign ( int i ) {
  return (i < 0) ? -1 : (i > 0) ? 1 : 0;
}

int main () {
  int S;
  cin >> S;
  for( int s=1; s<=S; s++ ){
    cout << "Scenario #" << s << ":\n";
    
    //--- Read players.
    int P, R;
    cin >> P >> R;
    string waste;
    getline( cin, waste );
    Player players[P];
    for( int p=0; p<P; p++ )
      getline( cin, players[p].name );
    
    //--- Process rounds.
    while( R-- > 0 ){
      int rp[50] = {}, rpMax = 0;
      int G;
      cin >> G;
      
      //--- Process games.
      for( int g=0; g<G; g++ ){
	int A, B;
	cin >> A >> waste >> B;
	
	for( int p=0; p<P; p++ ){
	  int a, b;
	  cin >> a >> waste >> b;
	  
	  if( sign( a-b ) == sign( A-B ) )
	    rp[p]++;
	  if( a==A && b==B )
	    rp[p] += 2;
	  rpMax = max(rp[p], rpMax);
	}
      }
      
      //--- Update scores.
      for( int p=0; p<P; p++ ){
	players[p].p += rp[p];
	players[p].d += (rp[p] == rpMax);
      }
    }
    
    //--- Sort and answer.
    stable_sort( players, players+P );
    for( int p=0; p<P; p++ )
      printf( "%d %d %s\n", players[p].p, players[p].d, players[p].name.c_str() );
    cout << endl;
  }
}
