编程介的小学生 2017-08-22 09:35 采纳率: 20.5%
浏览 720
已采纳

Crazy Painter

Crazy painter Henry Daub is planning to draw his new masterpiece. Like all paintings of Henry, the new masterpiece is going to be a rectangle of size m��n inches, each unit square of which will be painted with some color.

Henry would like to minimize the time needed to paint his masterpiece. He has already created the painting sketch and now he is planning the process of drawing. There are three technical tricks that Henry uses in creating his paintings.

In a turn he can paint either a horizontal line, a vertical line or a single unit square. Painting a horizontal line colors a number of horizontally adjacent unit squares to some color, painting a vertical lines colors a number of vertically adjacent squares, and painting a square just colors this square. Painting a horizontal line takes Henry h seconds, a vertical line can be painted in v seconds, and a single square is painted in s seconds.

Since the resulting picture must be accurate, it is not allowed to change the color of the square, that is, a single square may be painted several times, but it must be painted the same color each time. Help Henry to determine the time needed to paint the picture. Initially the canvas is empty, so each square must be colored.

Input

Input contains multiple test cases. The first line of the input is a single integer T (1 <= T <= 40) which is the number of test cases. T test cases follow, each preceded by a single blank line.

The first line of each case contains m, n, h, v and s (1 <= m, n <= 30, 1 <= h, v, s <= 105). Next m lines contain n characters each and describe the future masterpiece. The colors of the squares are identified using small letters of English alphabet.

Output

For each test case, on the first line print t - the time needed to paint the masterpiece and k - the number of turns needed to do this. Next k lines must contain the description of the turns. Each turn is first described with one of the letters 'h', 'v' or 's'. In the first two cases four integers numbers must follow - the coordinates of the leftmost topmost and the rightmost bottommost square of the line painted; in the last case just two integers are needed - the coordinates of the square painted. The last character of each line must be the color used in the turn.

Sample Input

2

4 4 3 5 2
aabc
aabc
bbbb
ccbc

3 4 11 8 3
aaaa
aaaa
aaaa

Sample Output

23 8
h 1 1 1 2 a
h 2 1 2 2 a
h 3 1 3 4 b
v 1 3 4 3 b
h 4 1 4 2 c
s 1 4 c
s 2 4 c
s 4 4 c

32 4
v 1 1 3 1 a
v 1 2 3 2 a
v 1 3 3 3 a
v 1 4 3 4 a

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-03 14:30
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测