#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int H,W; int A[404],B[404]; vector E[202020]; int in[202020]; int M[202020]; void solve() { int i,j,k,l,r,x,y; string s; cin>>H>>W; FOR(i,H) cin>>A[i]; FOR(i,W) cin>>B[i]; /* sort(A,A+H); reverse(A,A+H); sort(B,B+W); reverse(B,B+W); */ FOR(y,H) { for(x=1;x Q; FOR(i,H*W) if(in[i]==0) Q.push(i); while(Q.size()) { i=Q.front(); Q.pop(); M[i]=nex--; FORR(e,E[i]) if(--in[e]==0) Q.push(e); } FOR(y,H) { FOR(x,W) cout<