program arith;
type Tszam=string[1001];
var zero,inp,s1,s2:Tszam;
    tar:array[1..500] of Tszam;
   n,i,t:integer;
const space='                                                                                                       ';
   	vonal='--------------------------------------------------------------------------------------------------';

procedure kiir(const a:Tszam;hossz:integer;muv:char);
var n:integer;
begin
  if muv=#0 then n:=0 else n:=1;
  while n+length(a)<hossz do begin
    write(' ');
    inc(n);
  end;
  if muv<>#0 then write(muv);
  writeln(a);
end;

function cc(s:string;a,b:integer):string;
begin
  delete(s,1,a-1);
  delete(s,b+1,1001);
  cc:=s;
end;

procedure plusz(const a,b:Tszam);
var h,tmp,i,carry:integer;
    c,a1,b1:Tszam;
begin
  a1:=a;b1:=b;
  while length(a1)<length(b1) do a1:='0'+a1;
  while length(a1)>length(b1) do b1:='0'+b1;
  h:=length(a1);
  carry:=0;c:='';
  for i:=h downto 1 do begin
    tmp:=ord(a1[i])+ord(b1[i])-2*ord('0')+carry;
    carry:=tmp div 10;
    c:=chr(tmp mod 10+ord('0'))+c;
  end;
  if carry>0 then begin
    c:=chr(carry+ord('0'))+c;
  end;
  if length(b)=h then inc(h);
  kiir(a,h,#0);
  kiir(b,h,'+');
  for i:=1 to h do 
    write('-');
  writeln;
  kiir(c,h,#0);
  writeln;
end;

procedure minusz(const a,b:Tszam);
var h,i,tmp,carry:integer;
    c,a1,b1:Tszam;
begin
  a1:=a;b1:=b;
  while length(a1)<length(b1) do a1:='0'+a1;
  while length(a1)>length(b1) do b1:='0'+b1;
  h:=length(a1);
  carry:=0;c:='';
  for i:=h downto 1 do begin
    tmp:=ord(a1[i])-ord(b1[i])+carry;
    carry:=tmp div 10;
    c:=chr(tmp mod 10+ord('0'))+c;
  end;
  if length(b)=h then inc(h);
  kiir(a,h,#0);
  kiir(b,h,'-');
  for i:=1 to h do 
    write('-');
  writeln;
  kiir(c,h,#0);
  writeln;
end;

procedure szor1(var a:Tszam;const b:Tszam;c:integer);
var carry,i,tmp:integer;
begin
  a:='';
  carry:=0;
  for i:=length(b) downto 1 do begin
    tmp:=(ord(b[i])-ord('0'))*c+carry;
    carry:=tmp div 10;
    a:=chr(tmp mod 10+ord('0'))+a;
  end;
  while carry>0 do begin
    a:=chr(carry mod 10+ord('0'))+a;
    carry:=carry div 10;
  end;
  while (length(a)>1) and (a[1]='0') do delete(a,1,1);
end;

procedure plus(var c:Tszam;a1,b1:Tszam);
var h,tmp,i,carry:integer;
begin
  while length(a1)<length(b1) do a1:='0'+a1;
  while length(a1)>length(b1) do b1:='0'+b1;
  h:=length(a1);
  carry:=0;c:='';
  for i:=h downto 1 do begin
    tmp:=ord(a1[i])+ord(b1[i])-2*ord('0')+carry;
    carry:=tmp div 10;
    c:=chr(tmp mod 10+ord('0'))+c;
  end;
  if carry>0 then begin
    c:=chr(carry+ord('0'))+c;
  end;
end;

procedure szor(const a,b:Tszam);
var i,h,h1,t2:integer;
   s,tmp,t:Tszam;
begin
  s:='';
  tmp:='';
  for i:=length(b) downto 1 do begin
    szor1(tar[i],a,ord(b[i])-ord('0'));
    t:=tar[i]+tmp;
    plus(s,t,s);
    tmp:=tmp+'0';
  end;
  if length(b)+1>length(s) then h:=length(b)+1
  else h:=length(s);
  kiir(a,h,#0);
  kiir(b,h,'*');
  if length(a)>length(b)+1 then h1:=length(a)
  else h1:=length(b)+1;
  for i:=1 to h-h1 do write(' ');
  for i:=1 to h1 do write('-');
  writeln;
  if length(b)>1 then begin
  t2:=0;
  for i:=length(b) downto 1 do begin
    kiir(tar[i],h-t2,#0);
    inc(t2);
  end;
  if length(s)<h then write(' ') else write('-');
  for i:=2 to h do write('-');
  writeln;
  end;
  while (length(s)>1) and (s[1]='0') do delete(s,1,1);
  kiir(s,h,#0);
  writeln;
end;

Begin
  readln(n);
  for i:=1 to n do begin
    readln(inp);
    t:=pos('+',inp)+pos('-',inp)+pos('*',inp);
    s1:=cc(inp,1,t-1);s2:=cc(inp,t+1,1001);
    case inp[t] of 
      '+': begin 
             plusz(s1,s2);
           end;
      '-': begin
             minusz(s1,s2);
           end;
      '*': begin
             szor(s1,s2);
           end;
    end;
  end;
end.

