A puzzle is built from hexagonal tiles packed tightly together. Each tile shows one character: a digit, an =, or one of the arithmetic operators +, -, *, or /.
Consider a continuous path that passes through every tile exactly once, where each tile on the path is an immediate neighbor of the previous tile. Reading the characters along the path spells out a string, and the goal is to choose a path whose string is an acceptable equation as defined below. For instance, one path through a pattern might spell 6/3=9-7, while another might spell 3*21+10=73.
Even a modestly sized pattern hides many possible paths, so your task is to find the solution automatically.
Because the shorter (odd-numbered) rows are inset by half a tile relative to the longer (even-numbered) rows, two tiles are immediate neighbors exactly when either they lie in the same row side by side, or they lie in two consecutive rows with their horizontal positions differing by half a tile. An interior tile can therefore touch up to six others.
The tile arrangement and characters in every puzzle obey these rules:
= in the pattern.* characters in the pattern.For the string read along a path to be an acceptable equation, it must contain the single =, and the expressions on both sides must be in acceptable form and evaluate to the same integer. Acceptable form and evaluation are governed by these rules:
+, -, *, and / are binary operators only; a string in which + or - would act as a unary sign is not acceptable. For example, -2*3=-6 and 1=5+-4 are not acceptable.44-4/2=2+3*4 is acceptable, but 14=2+3*4 is not.10/5=12/6 and 7+3/5=3*4/6 are acceptable, whereas 5/2*4=10 is not (it would require a fractional intermediate result) and 5/2*4=8 is not (it would require truncating division).123+1=124 is not acceptable.0 immediately followed by another digit is not acceptable. For example, 3*05=15 is not acceptable.Under these rules, no intermediate or final value ever exceeds three million in magnitude.
The input contains one to fifteen datasets, followed by a line containing only 0.
The first line of each dataset holds two blank-separated integers r and c, where r is the number of rows in the pattern and c is the number of tiles in each odd-numbered row. The next r lines list the tile characters, one row per line, with the characters in a row separated by blanks. Odd-numbered rows also begin with an extra leading blank, mirroring the way the hexagons interlock. Every pattern satisfies the five arrangement rules above.
For each dataset, print a single line: the unique acceptable equation obtained by reading the tiles along the solving path. The line contains no spaces.