#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

typedef int           vert;
typedef vert          edge;
typedef vector<edge>  edges;
typedef vector<edges> graph;

bool augment( graph& G, int v, vector<vert>& matchTo, bool visited[] )
{
	for(int i=0; i<G[v].size(); ++i) {
		vert u = G[v][i];
		if( visited[u] ) continue;
		visited[u] = true;

		if( matchTo[u]<0 || augment(G, matchTo[u], matchTo, visited) )
			{ matchTo[v]=u, matchTo[u]=v; return true; }
	}
	return false;
}

template<int NV>
int biMatch( graph& G, int L ) // [0,L):left, [L,?):right
    // only left->right edges are used during computation
{
	vector<vert> matchTo(G.size(), -1);
	int ans = 0;
	for(vert v=0; v<L; ++v) {
		bool visited[NV] = {};
		if( augment(G, v, matchTo, visited) )
			++ans;
	}
	return ans;
}

class P8XMatrixRecovery { public:
	int H, W;
	vector <string> solve(vector <string> rows, vector <string> columns)
	{
		H = rows.size();
		W = rows[0].size();
		for(int y=0; y<H; ++y)
			for(int x=0; x<W; ++x)
				if( rows[y][x] == '?' ) {
					rows[y][x] = '0';
					if( !can(rows, columns) )
						rows[y][x] = '1';
				}
		return rows;
	}

	bool can(const vector<string>& rows, const vector<string>& columns)
	{
		graph G(W*2);
		for(int x1=0; x1<W; ++x1) {
			string left;
			for(int y=0; y<H; ++y)
				left += rows[y][x1];
			for(int x2=0; x2<W; ++x2)
				if( match(left, columns[x2]) ) 
					G[x1].push_back(x2+W);
		}
		return biMatch<60>(G, W) == W;
	}

	bool match( const string& l, const string& r )
	{
		for(int i=0; i<l.size(); ++i)
			if( l[i]!=r[i] && l[i]!='?' && r[i]!='?' )
				return false;
		return true;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <string>& Expected, const vector <string>& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, P8XMatrixRecovery().solve(rows, columns));}
int main(){

CASE(0)
	string rows_[] = {"10?"
,"?11"};
	  vector <string> rows(rows_, rows_+sizeof(rows_)/sizeof(*rows_)); 
	string columns_[] = {"01"
,"10"
,"1?"}
;
	  vector <string> columns(columns_, columns_+sizeof(columns_)/sizeof(*columns_)); 
	string __[] = {"101", "011" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	string rows_[] = {"0"
,"?"
,"1"};
	  vector <string> rows(rows_, rows_+sizeof(rows_)/sizeof(*rows_)); 
	string columns_[] = {"0?1"};
	  vector <string> columns(columns_, columns_+sizeof(columns_)/sizeof(*columns_)); 
	string __[] = {"0", "0", "1" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	string rows_[] = {"10"
,"01"};
	  vector <string> rows(rows_, rows_+sizeof(rows_)/sizeof(*rows_)); 
	string columns_[] = {"10"
,"01"};
	  vector <string> columns(columns_, columns_+sizeof(columns_)/sizeof(*columns_)); 
	string __[] = {"10", "01" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	string rows_[] = {"??0"
,"11?"
,"?01"
,"1?1"};
	  vector <string> rows(rows_, rows_+sizeof(rows_)/sizeof(*rows_)); 
	string columns_[] = {"1???"
,"?111"
,"0?1?"};
	  vector <string> columns(columns_, columns_+sizeof(columns_)/sizeof(*columns_)); 
	string __[] = {"010", "110", "101", "101" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	string rows_[] = {
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
	};
	  vector <string> rows(rows_, rows_+sizeof(rows_)/sizeof(*rows_)); 
	string columns_[] = {
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
		"??????????????????????????????",
	};
	  vector <string> columns(columns_, columns_+sizeof(columns_)/sizeof(*columns_)); 
  string __[] = {"?"};
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
string rows_[] = {"?"};
	  vector <string> rows(rows_, rows_+sizeof(rows_)/sizeof(*rows_)); 
	string columns_[] = {"?"};
	  vector <string> columns(columns_, columns_+sizeof(columns_)/sizeof(*columns_)); 
	string __[] = {"0"};
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(6)
	string rows_[] = {"??","??"};
	  vector <string> rows(rows_, rows_+sizeof(rows_)/sizeof(*rows_)); 
	string columns_[] = {"00","11"};
	  vector <string> columns(columns_, columns_+sizeof(columns_)/sizeof(*columns_)); 
	string __[] = {"01","01"};
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(7)
	string rows_[] = {"0??", "?0?"};
	  vector <string> rows(rows_, rows_+sizeof(rows_)/sizeof(*rows_)); 
	string columns_[] = {"01", "00", "10"};
	  vector <string> columns(columns_, columns_+sizeof(columns_)/sizeof(*columns_)); 
	string __[] = {"001", "100"};
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END

}
// END CUT HERE
