program arith;

var
  la,lb,max,przen,mmax,tmp,premax,n,i,j,k,q: integer;
  T : array[1..501,1..1002] of byte;
  a,b,cc: array[1..501] of byte;
  c,z: char;
begin
  readln(n);
  while (n>0) do
  begin
    i:=0;
    repeat
      inc(i);
      read(c);
      if ord(c)<48 then break;
      a[i]:=Ord(c)-48;
      a[i+1]:=11;
      la:=i;
    until FALSE;
    z:=c;
    i:=0;
    repeat
      inc(i);
      read(c);
      b[i]:=Ord(c)-48;
      b[i+1]:=11;
      lb:=i;
    until eoln;
    readln;
    for i:=1 to la do cc[i]:=a[i];
    for i:=la downto 1 do a[i]:=cc[la+1-i];
    for i:=1 to lb do cc[i]:=b[i];
    for i:=lb downto 1 do b[i]:=cc[lb+1-i];
    for i:=la+1 to 501 do a[i]:=11;
    for i:=lb+1 to 501 do b[i]:=11;
    
    if la>lb+1 then premax:=la else premax:=lb+1;
    case z of
    '+':
    begin   
      if la>lb then max:=la else max:=lb;
      przen:=0;
      for i:=1 to max do
      begin
        T[1,i]:=a[i]+b[i]+przen;
	if (a[i]=11) or (b[i]=11) then dec(t[1,i],11);
	przen:=T[1,i] div 10;
	T[1,i]:=T[1,i] mod 10;
      end;
      T[1,max+1]:=przen; 
      if przen>0 then inc(max);
      if premax<max then premax:=max;
      for i:=1 to premax-la do write(' ');
      for i:=la downto 1 do write(a[i]);
      writeln;
      for i:=1 to premax-lb-1 do write(' ');
      write('+');
      for i:=lb downto 1 do write(b[i]);
      writeln;
      for i:=1 to premax do write('-');
      writeln;
      for i:=premax downto max+1 do write(' ');
      for i:=max downto 1 do write(T[1,i]);
      writeln;
      writeln;
    end;
    '-':
    begin   
      if la>lb then max:=la else max:=lb;
      przen:=0;
      for i:=1 to max do
      begin
        tmp:=a[i];
	tmp:=tmp-b[i];
	tmp:=tmp-przen;
	if (a[i]=11) then dec(tmp,11);
	if (b[i]=11) then inc(tmp,11);
	if tmp<0 then begin inc(tmp,10); przen:=1 end  else przen:=0;
	T[1,i]:=tmp;
      end;
      T[1,max+1]:=przen;
      if przen>0 then inc(max);
      for i:=max downto 1 do if (T[1,i]>0) and (T[1,i]<11) then break;
      max:=i;
      if premax<max then premax:=max;
      for i:=1 to premax-la do write(' ');
      for i:=la downto 1 do write(a[i]);
      writeln;
      for i:=1 to premax-lb-1 do write(' ');
      write('-');
      for i:=lb downto 1 do write(b[i]);
      writeln;
      for i:=1 to premax do write('-');
      writeln;
      for i:=premax downto max+1 do write(' ');
      for i:=max downto 1 do write(T[1,i]);
      writeln;
      writeln;
    end;
    '*':
    begin
      max:=-1;
      for i:=1 to lb do
      begin
        for j:=1 to lb+la+1 do T[i,j]:=11;
	przen:=0;
	if b[i]>0 then
	begin
	for k:=1 to la do
	begin
	  T[i,k+i-1]:=b[i]*a[k]+przen;
	  przen:=T[i,k+i-1] div 10;
	  T[i,k+i-1]:=T[i,k+i-1] mod 10;
	end;
	T[i,la+i]:=przen;
	if przen=0 then T[i,la+i]:=11;
	end else begin T[i,i]:=0; T[i,i+1]:=11; end;
	for q:=la+i downto 1 do if T[i,q]<11 then break;
	if q>max then max:=q;
      end;
      przen:=0;
      for i:=1 to max do
      begin
         for j:=1 to lb do
	   if T[j,i]<>11 then inc(przen,T[j,i]);
	 T[501,i]:=przen mod 10;
	 przen:=przen div 10;
      end;
      T[501,max+1]:=przen;
      T[501,max+2]:=11;
      if przen=0 then T[501,max+1]:=11 else inc(max); 
      for i:=max downto 1 do if T[501,i]<>11 then break;
      mmax:=i;
      if max<premax then max:=premax;
      for i:=1 to max-la do write(' ');
      for i:=la downto 1 do write(a[i]);
      writeln;
      for i:=1 to max-lb-1 do write(' ');
      write('*');
      for i:=lb downto 1 do write(b[i]);
      writeln;
      for i:=1 to max-premax do write(' ');
      for i:=1 to premax do write('-');
      writeln;
      if lb>1 then begin
      for i:=1 to lb do
      begin
        for k:=max downto 1 do
	  if T[i,k]=11 then write(' ') else write(T[i,k]);
	writeln;
      end;
      for i:=1 to max do write('-');
      writeln;
      end;
      for i:=max downto mmax+1 do write(' ');
      for i:=mmax downto 1 do write(T[501,i]);
      writeln;
      writeln;	
      end;   
    end;     
    dec(n);
  end;
end.