import java.util.*;

class Solution
{
  private static class Node implements Comparable<Node> {
    public int tStart, tEnd, numPizzas;
    public Node(int ts, int te) {
      tStart = ts; tEnd = te;
    }
    public int compareTo(Node n) {
      return tEnd - n.tEnd;
    }
  }

  public static int toMinutes(int hhmm) {
    return 60*(hhmm / 100) + (hhmm % 100);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    for (int I = 1; I <= N; ++I) {

      int m = sc.nextInt();
      Node[] nodes = new Node[m];

      for (int i = 0; i < m; ++i) {
        int d = sc.nextInt(), s = sc.nextInt(), e = sc.nextInt();

        int startStamp = d*24*60 + toMinutes(s);
        int endStamp = d*24*60 + toMinutes(e);

        nodes[i] = new Node(startStamp, endStamp);
      }

      // It's always best to greedily go to the event that ends next.
      // Sort nodes by end time, and linearly walk the array afterwards.
      Arrays.sort(nodes);
      int currTime = 0;
      int numEvents = 0;
      for (Node node : nodes)
        if (node.tStart >= currTime) {
          ++numEvents;
          currTime = node.tEnd;
        }

      System.out.println("Scenario #" + I + ":");
      System.out.println(numEvents);
      System.out.println();
    }
  }
}
