Arithmetical CAPTCHA (LiveArchive 7214) by ynu_a
Contest: 3394    RunID: 2158377    Status: Accepted    Date: Sun Apr 09 15:13:51 JST 2017


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;

int n[5];
char op[] = {'+','-','='};

bool check(deque<char> &ops) {
  bool found = false;
  rep(i,3) if( ops[i] == '=' ) { found = true; break; }
  if( !found ) return false;
  set<int> S;
  int v = n[0];
  rep(i,3) {
    if( ops[i] == '+' ) {
      v += n[i+1];
    } else if( ops[i] == '-' ) {
      v -= n[i+1];
    } else {
      S.insert(v);
      v = n[i+1];
    }
  }
  S.insert(v);
  return S.size() == 1;
}

bool dfs(int cur,deque<char> &deq) {
  if( cur >= 3 ) {
    return check(deq);
  }
  rep(i,3) {
    deq.push_back(op[i]);
    if( dfs(cur+1,deq) ) return true;
    deq.pop_back();
  }
  return false;
}

void compute() {
  deque<char> deq;
  assert( dfs(0,deq) );
  cout << n[0] << " ";
  rep(i,3) {
    cout << deq[i] << " " << n[i+1];
    if( i != 2 ) cout << " ";
  } puts("");
}

int main() {
  int T,CNT=1;
  cin >> T;
  while( T-- ) {
    cout << "Case #" << CNT++ << ": ";
    rep(i,4) cin >> n[i];
    compute();
  }
  return 0;
}