Problem:
Problem D: Trapezoids

If you are a computer user, you should have seen pictures drawn with ASCII characters. Such a picture may not look as good as GIF or Postscript pictures, but is much easier to handle. ASCII pictures can easily be drawn using text editors, and can convey graphical information using only text-based media. Program s extracting information from such pictures may be useful.

We are interested in simple pictures of trapezoids, consisting only of asterisk('*') characters and blank spaces. A trapezoid (trapezium in the Queen's English) is a four-side polygon where at least one pair of its sides is parallel. Furthermore, the picture in this problem satisfies the following conditions.

All the asterisks in the picture belong to sides of some trapezoid.

Two sides of a trapezoid are horizontal and the other two are vertical or incline 45 degrees.

Every side is more than 2 characters long.

Two distinct trapezoids do not share any asterisk characters.

Sides of two trapezoids do not touch. That is, asterisks of one trapezoid do not appear in eight neighbors of asterisks of a different trapezoid. For example, the following arrangements never appear.

**** | **** | ******
* * | * * *** | * *
**** | ******* * | ****
**** | *** | ****
* * | | * *
**** | | ****

Some trapezoids may appear inside others. For example, the following is a valid picture.

*********
* *
* *** *
* * * *
* ***** *
* *
*********

Your task is to recognize trapezoids in the picture and to calculate the area of each trapezoid. The area of a trapezoid is the number of characters on or inside its four sides, including the areas of the trapezoids inside it, if any.

Input

The input contains several descriptions of pictures. Each of then starts with a line containing an integer h (1 ≤ h ≤ 1000), where h is the height (number of lines) of the picture. Each line of the picture consists only of asterisk and space characters, and contains less than 80 characters. The lines of the picture do not necessarily have the same length and may contain redundant space characters at the end. After the last picture, and integer zero terminates the input.

Output

For each picture, your program should produce output lines each containing two integers m and n is this order, which means there are n trapezoids of area m in the picture. output lines for one picture should be in ascending order on m and count all the trapezoids in the picture.

Output lines for two pictures should be separated by a line containing ten hyphen ('-') characters. This separator line should not appear before the output for the first picture nor after the output for the last.

Sample Input

7
********
* *
* *** *
* * * *
* *** *
* *
********
9

***
* *
***** *****
* *
*** *****
* *
* *
***
11
**** *******************
* * ********* * *
****** * * **** * ********* *
* *** * * * * * * *
*** * * * * **** ******* * * *** *** * *
* * * ***** * * * * * * * * * * *
*** * * *** * * *** *** * *
********* * * * *
* ********************* *
* *
*****************************
0

(Spacing between lines in pictures is made narrower for better appearance. Note that a blank line exists as the first line of the second picture.)

Output for the Sample Input

9 1
56 1
----------
12 2
15 1
----------
9 3
12 2
15 2
63 1
105 1
264 1

Solution in Ruby (judge verdict: Accepted)

def dfs(fld, check, n, m, depth)
  ok = true
  n.times do |y|
    m.times do |x|
      if check[y][x] == depth && fld[y][x] == '*'
        l = r = x
        loop do
          check[y][r] = depth + 1
          break if fld[y][r + 1] != '*'
          r += 1
        end
        ml = mr = -2
        (l-1..r+1).each do |i|
          ml = i - l if fld[y + 1][i] == '*' && ml == -2
          mr = i - r if fld[y + 1][i] == '*' && ml != -2
        end
        yy = y + 1; xl = l + ml; xr = r + mr
        loop do
          check[yy][xl] = check[yy][xr] = depth + 1
          (xl+1...xr).each{ |k| check[yy][k] = depth + 2 }
          if fld[yy + 1][xl + ml] != '*'
            (xl+1...xr).each{ |k| check[yy][k] = depth + 1 }
            break
          end
          yy += 1; xl += ml; xr += mr
        end
        s = ((r - l + 1) + (xr - xl + 1)) * (yy - y + 1) / 2
        $ret[s] ||= 0
        $ret[s] += 1
        ok = false
      end
    end
  end
  return true if ok
  return true if dfs(fld, check, n, m, depth + 2)
end

l = false
while n = gets.to_i
  break if n == 0
  if l
    10.times{ print '-' }
    puts
  end
  l = true
  fld = n.times.map{ gets.chomp.split('').unshift(' ').push(' ') }
  m = fld.map{ |f| f.size }.max
  fld.each{ |f| (m - f.size).times{ f.push(' ') } }
  fld = [ [' '] * m, *fld, [' '] * m ]
  $ret = {}
  check = (n+2).times.map{ [0] * m }
  dfs(fld, check, n+2, m, 0)
  $ret.sort.each{ |k, v| puts "#{k} #{v}" }
end