let swap a x y =
  let temp = a.(x) in
  a.(x) <- a.(y);a.(y) <- temp
;;
let () =
  let rec generate n a q =
    if n = 1 then Queue.push (Array.copy a) q
    else
      let rec loop i =
        generate (n-1) a q;
        if i = (n-1) then ()
        else
          begin
            if n mod 2 = 0 then
              swap a i (n-1)
            else
              swap a 0 (n-1)
           ;loop (i+1)
          end
      in loop 0
  in  
  let get_op i = match i with
    0 -> "+"
    |1 -> "-"
    |2 -> "*"
    |_ -> "undefined"
  in  let calc a b c d =
    let ops = [|(+);(-);( * )|] in
    let rec loop = function
      (-1, 2, 2) -> (0,"","","")
    | (i,j,k) -> if j = -1 then loop (i-1,2,2)
                 else if k = -1 then loop (i, j-1, 2)
                 else if (ops.(k) (ops.(j) (ops.(i) a b) c) d) = 10 then (1,get_op i,get_op j,get_op k)
                 else if (ops.(j) (ops.(i) a b) (ops.(k) c d)) = 10 then (2,get_op i,get_op j,get_op k)
                 else loop (i,j,k-1)
    in loop (2,2,2)
  in
  let rec read () =
    let (w,x,y,z) = Scanf.scanf "%d %d %d %d\n" (fun w x y z -> (w,x,y,z)) in
    if w = 0 then ()
    else
      begin
        let q = Queue.create () in
        generate 4 [|w;x;y;z|] q;
        let rec loop () =
          if Queue.is_empty q then Printf.printf "0\n"
          else
            begin
              let a = Queue.pop q in
              let (n,op1,op2,op3) = calc a.(0) a.(1) a.(2) a.(3) in
              if n = 1 then
                Printf.printf "(((%d %s %d) %s %d) %s %d)\n" a.(0) op1 a.(1) op2 a.(2) op3 a.(3)
              else if n = 2 then
                Printf.printf "((%d %s %d) %s (%d %s %d))\n" a.(0) op1 a.(1) op2 a.(2) op3 a.(3)
              else
                loop ()
            end
        in loop ();
        read ()
      end
  in read ()
;;