program daugianariai;
  { 67 u‘davinys }
  const  kiek = 8;        { operacij— su daugianariais skai‡ius }
         nmax = 10;       { di‘iausias daugianario laipsnis }
         epsilon = 0.1;   { skai‡iavim— tikslumas }
  type daug = record     { daugianaris }
                n : 0..nmax;                { daugianario laipsnis }
                k : array [0..nmax] of real { ir koeficientai      }
              end;

  function max (x, y : integer) : integer;
    { randa didesnj iž dviej— skai‡i— }
  begin
    if x < y
      then max := y
      else max := x
  end;

  procedure normal (var c : daug);
    { randa daugianario c laipsn }
    { skai‡iavimai atliekami epsilon tikslumu }
  begin
    while (abs (c.k[c.n]) < epsilon) and (c.n > 0) do
      c.n := c.n - 1
  end;

  procedure sudetis (a, b : daug; var c : daug);
    { sudeda daugianarius a ir b }
    var i : 0..nmax;
  begin
    for i := 0 to nmax do
      begin
        c.k[i] := 0;
        if i <= a.n
          then c.k[i] := c.k[i] + a.k[i];
        if i <= b.n
          then c.k[i] := c.k[i] + b.k[i]
      end;
    { sumos laipsnis lygus didesniajam iž daugianari— laipsniui }
    c.n :=  max (a.n, b.n);
    { rezultatas perskai‡iuojamas vieno skaitmens po kablelio tikslumu }
    normal (c)
  end;

  procedure atimtis (a, b : daug; var c : daug);
    var i : 0..nmax;
  begin
    for i := 0 to nmax do
      begin
        c.k[i] := 0;
        if i <= a.n
          then c.k[i] := c.k[i] + a.k[i];
        if i <= b.n
          then c.k[i] := c.k[i] - b.k[i]
      end;
    c.n := max (a.n, b.n);
    normal (c)
  end;

  procedure daugyba (a, b : daug; var c : daug);
    var i, j : 0..nmax;
  begin
    for i := 0 to nmax do
      c.k[i] := 0;
    { dauginant daugianari— laipsniai susideda }
    c.n := a.n + b.n;
    for i := 0 to a.n do
      for j := 0 to b.n do
        c.k[i+j] := c.k[i+j] + a.k[i] * b.k[j];
    normal(c)
  end;

  procedure dalyba (a, b : daug; var c : daug);
    var t : daug;
        i : 0..nmax;
  begin
    for i := 0 to nmax do
      c.k[i] := 0;
    { dalijant daugianari— laipsniai atsiima }
    c.n := a.n - b.n;
    while a.n >= b.n do
      begin
        t.n := a.n - b.n;
        for i := 0 to nmax do
          t.k[i] := 0;
        t.k[t.n] := a.k[a.n]/b.k[b.n];
        sudetis (c, t, c);
        daugyba (b, t, t);
        atimtis (a, t, a)
      end;
    normal(c)
  end;

  procedure dalliek (a, b : daug; var c : daug);
    var dalmuo, sandauga : daug;
  begin
    dalyba (a, b, dalmuo);
    daugyba (b, dalmuo, sandauga);
    atimtis (a, sandauga, c);
    normal(c)
  end;
{----------------------------------------------------------}
  var prad, rez : text;
      i, j : integer;
      oper : char;       { + - * / \ }
      a, b, c : daug;
begin
  assign (prad, 'daug.dat');
  assign (rez, 'daug.rez');
  reset (prad);
  rewrite (rez);
  for i := 1 to kiek do  { reikia atlikti tiek operacij— }
    begin
      readln (prad, oper); { perskaitoma operacija }
      read (prad, a.n);    { pirmasis daugianaris }
      for j := a.n downto 0 do
        read (prad, a.k[j]);
      readln (prad);
      read (prad, b.n);     { antrasis daugianaris }
      for j := b.n downto 0 do
        read (prad, b.k[j]);
      readln (prad);
      { atliekama operacija }
      case oper of
        '+' : sudetis (a, b, c);
        '-' : atimtis (a, b, c);
        '*' : daugyba (a, b, c);
        '/' : dalyba (a, b, c);
        '\' : dalliek (a, b, c);
      end;
      { spaudinami rezultatai }
      write (rez, c.n : 3);
      for j := c.n downto 0 do
        write (rez, c.k[j] : 6 : 1);
      writeln (rez)
    end;
  close (rez)
end.