// Arup Guha
// 1/10/04
// Solution to Missile problem using Dynamic Programming for the
// Programming Team lecture on Dynamic Programming.

using namespace std;

#include <fstream>
#include <iostream>

int main() {
  ifstream fin("catch.in");
  ofstream fout("catchdp.out");
  int *values = new int[10000];
  int testnum = 1;
  fin >> values[0];

  while (values[0] != -1) {
    int size = 1;
    fin >> values[size];
    while (values[size] != -1) {
      size++;
      fin >> values[size];
    }

    // Each array element k stores the maximum number of missiles that
    // can be caught of the first k+1 missiles assuming that the (k+1)st
    // missile is intercepted.
    int *aux = new int[size];
    aux[0] = 1;
    int i,j;

    // Loop through each element to fill in the auxiliary array.
    for (i=1; i<size; i++) {
      int tempmax = 1;

      // Loop through all possible previous ones for the best.
      for (j=0; j<i; j++)

        // In order to be a candidate, the new missile must be lower
        // than the previous last missile and using this set of missiles
        // must be better than anything previously seen.
        if (values[j] >= values[i] && (aux[j]+1 > tempmax))
          tempmax = aux[j] + 1;

      // Set this value to the best found.
      aux[i] = tempmax;
    }

    // Now we must search for the maximum of all the entries in aux, since
    // the best answer may not involve taking the last missile.
    int realmax = 1;
    for (i=1; i<size; i++)
      if (aux[i] > realmax)
        realmax = aux[i];

    // Output the solution for the data set.
    fout << "Test #" << testnum << ":" << endl;
    fout << "  maximum possible interceptions: ";
    fout << realmax << endl << endl;
    // Read in the next test set.
    delete [] aux;
    testnum++;
    fin >> values[0];
  }

  return 0;
}
