Simple Arithmetic

Time limit1sMemory limit128 MB

Problem

A calculator needs to evaluate expressions over very large numbers. To make its output easy to read, each result is laid out exactly the way the calculation would be written out by hand.

Write the core of this calculator. Given two numbers and an operation, compute the result and print it in the format described below.

  • For addition and subtraction, the two numbers are written one below the other.
  • Multiplication is more involved: first form one partial result for every digit of the second number, then add those partial results together.

Input

The first line contains a single positive integer T, the number of expressions that follow.

Each of the next T lines contains one expression made of a positive integer, an operator (one of +, -, *), and a second positive integer, with no spaces anywhere on the line.

Every number has at most 500 digits and no number starts with a zero. When the operator is -, the second number is always smaller than the first.

Output

For every expression print the layout below, and separate the outputs of consecutive expressions with a single blank line.

Write the two operands on two lines, the second directly beneath the first, with their last digits (the units) aligned in the same column. Place the operator immediately in front of the first digit of the second number. Below the second number draw a horizontal rule made of dashes (-).

Addition and subtraction. Put the result directly under the rule, with its last digit aligned to the last digit of the operands.

Multiplication. Multiply the first number by each digit of the second number. Print the partial products one under another, starting with the product of the units digit of the second number. Each partial product is aligned so that its last digit sits in the same column as the digit of the second number it came from. A partial product never has leading zeros; if that digit is 0, the partial product is the single character 0. If the second number has more than one digit, draw a second horizontal rule under the partial products and print their sum beneath it.

Every line must begin with as few leading spaces as the alignment allows. Each horizontal rule spans exactly from the leftmost to the rightmost column occupied by the line directly above it and the line directly below it — neither longer nor shorter.