#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_cxx;

#define IOC std::ios::sync_with_stdio(false)
typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int uit;
typedef long double ld;
//typedef pair<int,int> pii;
const int INF = 0x3f3f3f3f;
const double enf = 1e-8;
const double pi = acos(-1.0);
inline LL read()
{
    LL X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(LL x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
//-------head------------

const int maxn = 2e5 + 10;
struct grap{
    int head[maxn],tot = 1;
    struct edge{
        int from,to,id;
    }e[maxn];
    inline void add(int u,int v,int id){
        e[++tot].from = head[u];
        e[tot].to = v;
        e[tot].id = id;
        head[u] = tot;
    }
    inline void dbadd(int u,int v,int id){
        add(u,v,id);   add(v,u,id);
    }
}g;

int vis[maxn];
struct node{
    int u,v;
}dict[maxn];

inline void dfs(int x,int k){
    for(int i = g.head[x]; i; i = g.e[i].from){
        int id = g.e[i].id,v = g.e[i].to;
        if(!vis[id]){
            if(dict[id].u == x){
                vis[id] = k;
            }
            else{
                vis[id] = -k;
            }
            dfs(v,-k);
        }
    }
}
int main()
{
    int n = read(),m = read();
    for(int u,v,i = 0; i < m; ++i){
        u = read(),v = read();
        dict[i].u = u,dict[i].v = v;
        g.dbadd(u,v,i);
    }
    cout << "YES" << endl;
    dfs(1,1);
    for(int i = 0; i < m; ++i){
        printf("%d",vis[i] == 1 ? 1 : 0);
    }

    return 0;
}


#include <bits/stdc++.h>
//#include<algorithm>
//#include<math.h>
//#include<stdio.h>
//#include<ctype.h>
//#include<string.h>
//#include<iostream>
using namespace std;
//using namespace __gnu_cxx;

#define IOC std::ios::sync_with_stdio(false)
typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int uit;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 0x3f3f3f3f;
const double enf = 1e-8;
const double pi = acos(-1.0);
inline LL read()
{
    LL X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(LL x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
//-------head------------

const int maxn = 2e5 + 10;
struct grap{
    int head[maxn],tot = 1;
    struct edge{
        int from,to,id;
    }e[maxn << 1];
    inline void add(int u,int v,int id){
        e[++tot].from = head[u];
        e[tot].to = v;
        e[tot].id = id;
        head[u] = tot;
    }
    inline void dbadd(int u,int v,int id){
        add(u,v,id);   add(v,u,id);
    }
}g;

int vis[maxn];
struct node{
    int u,v;
}dict[maxn];

inline void dfs(int x,int k){
    vis[x] = k;
    for(int i = g.head[x]; i; i = g.e[i].from){
        int id = g.e[i].id,v = g.e[i].to;
        if(vis[v])   continue;
        dfs(v,-k);
    }
}
int main()
{
    int n = read(),m = read();
    for(int u,v,i = 0; i < m; ++i){
        u = read(),v = read();
        dict[i].u = u,dict[i].v = v;
        g.dbadd(u,v,i);
    }
    dfs(1,1);
    for(int i = 0; i < m; ++i){
        if(vis[dict[i].u] == vis[dict[i].v]){
            return cout << "NO" << endl,0;
        }
    }
    cout << "YES" << endl;
    for(int i = 0; i < m; ++i){
        printf("%d",vis[dict[i].u] == 1 ? 1 : 0);
    }

    return 0;
}


#include <bits/stdc++.h>
//#include<algorithm>
//#include<math.h>
//#include<stdio.h>
//#include<ctype.h>
//#include<string.h>
//#include<iostream>
using namespace std;
//using namespace __gnu_cxx;

#define IOC std::ios::sync_with_stdio(false)
typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int uit;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 0x3f3f3f3f;
const double enf = 1e-8;
const double pi = acos(-1.0);
inline LL read()
{
    LL X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(LL x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
//-------head------------

const int maxn = 2e5 + 10;
struct grap{
    int head[maxn],tot = 1;
    struct edge{
        int from,to,id;
    }e[maxn << 1];
    inline void add(int u,int v,int id){
        e[++tot].from = head[u];
        e[tot].to = v;
        e[tot].id = id;
        head[u] = tot;
    }
    inline void dbadd(int u,int v,int id){
        add(u,v,id);   add(v,u,id);
    }
}g;

int vis[maxn],in[maxn];
struct node{
    int u,v;
}dict[maxn];

bool flag = 0;
inline bool judge(int x,int fa){
    for(int i = g.head[x]; i; i = g.e[i].from){
        int v = g.e[i].to;
        if(v == fa) continue;
        if(!vis[v]){
            vis[v] = 1;
            if(judge(v,x))  return true;
        }
        else{
            return true;
        }
    }
    return false;
}
inline void dfs(int x,int k){
    in[x] = 1;
    for(int i = g.head[x]; i; i = g.e[i].from){
        int id = g.e[i].id,v = g.e[i].to;
        if(in[v])   continue;
        in[v] = 1;
        if(vis[id] == 0){
            if(dict[id].u == x){
                vis[id] = k;
            }
            else{
                vis[id] = -k;
            }
            dfs(v,-k);
        }
    }
}
int main()
{
    int n = read(),m = read();
    for(int u,v,i = 0; i < m; ++i){
        u = read(),v = read();
        dict[i].u = u,dict[i].v = v;
        g.dbadd(u,v,i);
    }
    if(judge(1,0)){
        return cout << "NO" << endl,0;
    }
    cout << "YES" << endl;
    memset(vis,0,sizeof vis);
    dfs(1,1);
    for(int i = 0; i < m; ++i){
        printf("%d",vis[i] == 1 ? 1 : 0);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 1;
    queue<ii> q;
    q.push(mp(u,dir));
    //visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;

            if(!visited[v]){
            	if(state==1){
            		p_s[mp(v,s)] = dir^state;
	            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
	            }else{
	            	p_s[mp(s,v)] = dir^state;
	            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
	            }
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

void DFS(int u,int dir){
    visited[u]++;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        int state = adj[u][i].snd;
        if(state==1){
    		if(p_s.count(mp(u,v))==0) p_s[mp(v,u)] = dir^state;
        	//cout<<v<<":"<<s<<" = "<<dir<<endl;
        }else{
        	if(p_s.count(mp(v,u))==0) p_s[mp(u,v)] = dir^state;
        	//cout<<s<<":"<<v<<" = "<<dir<<endl;
        }
        if(!visited[v]){

            DFS(v,1-dir);
        }
    }
}

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+3){
		if(!visited[i]) DFS(i,1);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 1;
    queue<ii> q;
    q.push(mp(u,dir));
    //visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;
            //if(state==1){
            	p_s[mp(v,s)] = dir^state;
            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
            //}else{
            	p_s[mp(s,v)] = dir^state;
            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
            //}
            if(!visited[v]){
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

void DFS(int u,int dir){
    visited[u]++;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        int state = adj[u][i].snd;
        p_s[mp(v,u)] = dir^state;
        p_s[mp(u,v)] = dir^state;
        if(!visited[v]){
            DFS(v,1-dir);
        }
    }
}

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+3){
		if(!visited[i]) DFS(i,1);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}/*else{
			cout<<"NO"<<endl;
			return 0;
		}*/
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 1;
    queue<ii> q;
    q.push(mp(u,dir));
    //visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;
            //if(state==1){
            	p_s[mp(v,s)] = dir^state;
            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
            //}else{
            	p_s[mp(s,v)] = dir^state;
            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
            //}
            if(!visited[v]){
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

/*void DFS(int u,int cl){
    visited[u]=cl+1;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        if(!visited[v]){
            DFS(v,1-cl);
        }
    }
}*/

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+1){
		if(!visited[i]) BFS(i);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 0;
    queue<ii> q;
    q.push(mp(u,dir));
    visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;
            if(state){
            	p_s[mp(v,s)] = dir^state;
            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
            }else{
            	p_s[mp(s,v)] = dir^state;
            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
            }
            if(!visited[v]){
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

/*void DFS(int u,int cl){
    visited[u]=cl+1;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        if(!visited[v]){
            DFS(v,1-cl);
        }
    }
}*/

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+1){
		if(!visited[i]) BFS(i);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2]<<" ";

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 1;
    queue<ii> q;
    q.push(mp(u,dir));
    //visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;

            if(!visited[v]){
            	if(state==1){
            		p_s[mp(v,s)] = dir^state;
	            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
	            }else{
	            	p_s[mp(s,v)] = dir^state;
	            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
	            }
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

bool DFS(int u,int dir){
    visited[u]++;
    bool check=1;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        int state = adj[u][i].snd;
        p_s[mp(v,u)] = dir^state;
        p_s[mp(u,v)] = dir^state;
        if(!visited[v]){

            check = check && DFS(v,1-dir);
        }
    }

    for(int i=0;i<adj[u].size()-1;i++){
        int v=adj[u][i].fst;
        int v2=adj[u][i+1].fst;
        //cout <<u<<" in "<<v<<":"<<v2<<" ";
        //cout<< (p_s[mp(u,v)]^(adj[u][i].snd))<< (p_s[mp(u,v2)]^(adj[u][i+1].snd))<<endl;
        check = check && ((p_s[mp(u,v)]^(adj[u][i].snd)) == (p_s[mp(u,v2)]^(adj[u][i+1].snd)));
    }
    return check;
}

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+1){
		if(!visited[i]){
			if(!DFS(i,1)){
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 1;
    queue<ii> q;
    q.push(mp(u,dir));
    //visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;
            //if(state==1){
            	p_s[mp(v,s)] = dir^state;
            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
            //}else{
            	p_s[mp(s,v)] = dir^state;
            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
            //}
            if(!visited[v]){
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

void DFS(int u,int dir){
    visited[u]++;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        int state = adj[u][i].snd;
        p_s[mp(v,u)] = dir^state;
        p_s[mp(u,v)] = dir^state;
        if(!visited[v]){
            DFS(v,1-dir);
        }
    }
}

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+3){
		if(!visited[i]) DFS(i,1);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 1;
    queue<ii> q;
    q.push(mp(u,dir));
    visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;
            if(state==1){
            	p_s[mp(v,s)] = dir^state;
            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
            }else{
            	p_s[mp(s,v)] = dir^state;
            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
            }
            if(!visited[v]){
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

/*void DFS(int u,int cl){
    visited[u]=cl+1;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        if(!visited[v]){
            DFS(v,1-cl);
        }
    }
}*/

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+1){
		if(!visited[i]) BFS(i);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;
bool flag;

void DFS(int u,int dir){
    visited[u]=dir+1;;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        int state = adj[u][i].snd;
        if(!visited[v]){
        	DFS(v,1-dir);
        }else if(visited[v] == dir+1){
        	flag = 0;
        }
    }
}

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	flag =1;
	REP(i,1,n+1){
		if(!visited[i])
			DFS(i,1);
	}

	if(!flag) {
		cout<<"NO"<<endl;
		return 0;
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<(visited[paths[i][0]]>visited[paths[i][1]]);
	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 0;
    queue<ii> q;
    q.push(mp(u,dir));
    visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;
            if(state){
            	p_s[mp(v,s)] = dir^state;
            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
            }else{
            	p_s[mp(s,v)] = dir^state;
            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
            }
            if(!visited[v]){
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

/*void DFS(int u,int cl){
    visited[u]=cl+1;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        if(!visited[v]){
            DFS(v,1-cl);
        }
    }
}*/

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+1){
		if(!visited[i]) BFS(i);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 1;
    queue<ii> q;
    q.push(mp(u,dir));
    //visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;

            if(!visited[v]){
            	if(state==1){
            	p_s[mp(v,s)] = dir^state;
	            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
	            }else{
	            	p_s[mp(s,v)] = dir^state;
	            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
	            }
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

void DFS(int u,int dir){
    visited[u]++;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        int state = adj[u][i].snd;
        p_s[mp(v,u)] = dir^state;
        p_s[mp(u,v)] = dir^state;
        if(!visited[v]){
            DFS(v,1-dir);
        }
    }
}

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+3){
		if(!visited[i]) BFS(i);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back((x))
#define REP(i,x,y) for(long long (i)=(x);(i)<(y);(i)++)
#define PER(i,x,y) for(long long (i)=(x);(i)>=(y);(i)--)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define sqr(x) ((x)*(x))
#define mp(x,y) make_pair((x),(y))
#define mt(x,y,z) mp(mp((x),(y)),z)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define trace(x) cout << #x << " = " << x << endl
//#define NDEBUG 1
#define fst first
#define snd second
#define sz(v) ((int)v.size())
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define MAX 100000000
typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ii,ull> tri;
typedef vector<ii> vii;
typedef vector<tri> vt;

int n,m;
vector<ii> adj[300009]; //El tamanho depende de los limites del problema, por ahora lo dejo como 10 a la 5
int visited[300009];
int paths[300009][3];
map<ii,int> p_s;

void BFS(int u){
	int dir = 1;
    queue<ii> q;
    q.push(mp(u,dir));
    //visited[u]++;

    while(!q.empty()){
        int s=q.front().fst;
        dir = q.front().snd;
        q.pop();
        for(int i=0;i<adj[s].size();i++){
            int v=adj[s][i].fst;
            int state = adj[s][i].snd;
            //if(state==1){
            	p_s[mp(v,s)] = dir^state;
            	//cout<<v<<":"<<s<<" = "<<dir<<endl;
            //}else{
            	p_s[mp(s,v)] = dir^state;
            	//cout<<s<<":"<<v<<" = "<<dir<<endl;
            //}
            if(!visited[v]){
                visited[v]++;
                q.push(mp(v,1-dir));
            }
        }
    }
}

/*void DFS(int u,int cl){
    visited[u]=cl+1;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i].fst;
        if(!visited[v]){
            DFS(v,1-cl);
        }
    }
}*/

int main(){
	cin>>n>>m;
	memset(visited,0,sizeof(visited));
	REP(i,0,m){
		int u,v; cin>>u>>v;
		adj[u].push_back(mp(v,0));
		adj[v].push_back(mp(u,1));
		paths[i][0] = u;
		paths[i][1] = v;
	}
	REP(i,1,n+3){
		if(!visited[i]) BFS(i);
	}

	REP(i,0,m){
		int u = paths[i][0];
		int v = paths[i][1];
		if(p_s.count(mp(u,v))>0){
			paths[i][2] =p_s[mp(u,v)];
			//cout<<paths[i][2]<<endl;
		}else{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
	REP(i,0,m){
			cout<<paths[i][2];

	}cout <<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int N=2e5+5;

int n,m;

int col[N];

struct Edge{
    int v,next;
    Edge(){}
    Edge(int v_,int next_) {
        v=v_,next=next_;
    }
}edges[N];
int tot;
int head[N];
void addedge(int u,int v) {
    edges[tot]=Edge(v,head[u]);
    head[u]=tot++;
}
void init() {
    tot=0;
    memset(head,-1,sizeof(head));
}

bool dfs(int u,int c) {
    //printf("%d  %d ==\n",u,c);
    col[u]=c;
    for(int i=head[u];~i;i=edges[i].next) {
        int v=edges[i].v;
        if(!col[v]) dfs(v,c^3);
        else if(col[v]!=(c^3)) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    init();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        addedge(u,v);
        addedge(v,u);
    }
    if(dfs(1,1))
    {
        cout<<"YES\n";
        for(int i=0;i<m;i++)
            cout<<col[edges[i*2].v]%2;
    }
    else
        cout<<"NO\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int N=2e5+5;

int n,m;

int col[N];
int u[N],v[N];
vector<int> adj[N];

bool dfs(int u,int c) {
    //printf("%d  %d ==\n",u,c);
    col[u]=c;
    for(int i=0;i<adj[u].size();i++) {
        int v=adj[u][i];
        if(!col[v]) dfs(v,c^3);
        else if(col[v]==col[u]) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>u[i]>>v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    if(dfs(1,1))
    {
        cout<<"YES\n";
        for(int i=0;i<m;i++)
            cout<<col[u[i]]%2;
    }
    else
        cout<<"NO\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int N=2e5+5;

int n,m;

int col[N];

struct Edge{
    int v,next;
    Edge(){}
    Edge(int v_,int next_) {
        v=v_,next=next_;
    }
}edges[N];
int tot;
int head[N];
void addedge(int u,int v) {
    edges[tot]=Edge(v,head[u]);
    head[u]=tot++;
}
void init() {
    tot=0;
    memset(head,-1,sizeof(head));
}

bool dfs(int u,int c) {
    //printf("%d  %d ==\n",u,c);
    col[u]=c;
    for(int i=head[u];~i;i=edges[i].next) {
        int v=edges[i].v;
        if(!col[v]) dfs(v,c^3);
        if(col[v]!=(c^3)) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    init();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        addedge(u,v);
        addedge(v,u);
    }
    if(dfs(1,1))
    {
        cout<<"YES\n";
        for(int i=0;i<m;i++)
            cout<<col[edges[i*2].v]%2;
    }
    else
        cout<<"NO\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int N=2e5+5;

int n,m;

int col[N];

struct Edge{
    int v,next;
    Edge(){}
    Edge(int v_,int next_) {
        v=v_,next=next_;
    }
}edges[N];
int tot;
int head[N];
void addedge(int u,int v) {
    edges[tot]=Edge(v,head[u]);
    head[u]=tot++;
}
void init() {
    tot=0;
    memset(head,-1,sizeof(head));
}

bool dfs(int u,int c) {
    //printf("%d  %d ==\n",u,c);
    col[u]=c;
    for(int i=head[u];~i;i=edges[i].next) {
        int v=edges[i].v;
        if(!col[v]) dfs(v,c^3);
        if(col[v]!=c^3) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    init();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        addedge(u,v);
        addedge(v,u);
    }
    if(dfs(1,1))
    {
        cout<<"YES\n";
        for(int i=0;i<m;i++)
            cout<<col[edges[i*2].v]%2;
    }
    else
        cout<<"NO\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int N=2e5+5;

int n,m;

int col[N];
int u[N],v[N];
vector<int> adj[N];

bool dfs(int u,int c) {
    //printf("%d  %d ==\n",u,c);
    col[u]=c;
    for(int i=0;i<adj[u].size();i++) {
        int v=adj[u][i];
        if(!col[v]&&!dfs(v,c^3)) return false;
        else if(col[v]==col[u]) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>u[i]>>v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    if(dfs(1,1))
    {
        cout<<"YES\n";
        for(int i=0;i<m;i++)
            cout<<col[u[i]]%2;
    }
    else
        cout<<"NO\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int N=2e5+5;

int n,m;

int col[N];
int u[N],v[N];
vector<int> adj[N];

bool dfs(int u,int c) {
    //printf("%d  %d ==\n",u,c);
    col[u]=c;
    for(int i=0;i<adj[u].size();i++) {
        int v=adj[u][i];
        if(!col[v]) dfs(v,c^3);
        else if(col[v]!=(c^3)) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>u[i]>>v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    if(dfs(1,1))
    {
        cout<<"YES\n";
        for(int i=0;i<m;i++)
            cout<<col[u[i]]%2;
    }
    else
        cout<<"NO\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int N=2e5+5;

int n,m;

int col[N];
int u[N],v[N];
vector<int> adj[N];

bool dfs(int u,int c) {
    //printf("%d  %d ==\n",u,c);
    col[u]=c;
    for(int i=0;i<adj[u].size();i++) {
        int v=adj[u][i];
        if(!col[v]) if(!dfs(v,c^3)) return false;
        else if(col[v]==col[u]) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>u[i]>>v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    if(dfs(1,1))
    {
        cout<<"YES\n";
        for(int i=0;i<m;i++)
            cout<<col[u[i]]%2;
    }
    else
        cout<<"NO\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int N=2e5+5;

int n,m;

int col[N];

struct Edge{
    int v,next;
    Edge(){}
    Edge(int v_,int next_) {
        v=v_,next=next_;
    }
}edges[N];
int tot;
int head[N];
void addedge(int u,int v) {
    edges[tot]=Edge(v,head[u]);
    head[u]=tot++;
}
void init() {
    tot=0;
    memset(head,-1,sizeof(head));
}

bool dfs(int u,int c) {
    //printf("%d  %d ==\n",u,c);
    col[u]=c;
    for(int i=head[u];~i;i=edges[i].next) {
        int v=edges[i].v;
        if(col[v]&&col[v]!=(c^3)) return false;
        if(!col[v]) dfs(v,c^3);
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    init();
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        addedge(u,v);
        addedge(v,u);
    }
    if(dfs(1,1))
    {
        cout<<"YES\n";
        for(int i=0;i<m;i++)
            cout<<col[edges[i*2].v]%2;
    }
    else
        cout<<"NO\n";
}


#include<bits/stdc++.h>
#define pb push_back
#define siz 200009
#define inf 1e9+8
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll long long
#define pii pair<int,int >
#define scad(n) scanf("%d",&n)
#define scad2(m,n) scanf("%d%d",&m,&n);
#define mid (start+endd)/2
#define MOD 1000000007
#define fileout freopen("output.txt","w",stdout)
#define mem(x,i) memset(x,i,sizeof x)
#define pi acos(-1.0)
#define ff first
#define ss second
using namespace std;
vector<pii>vec;
map<pii,int> mp1;
//map<pii,bool>mp2;
bool vis[siz]= {0};
vector<int>adj[siz],adu[siz];
int fg=1,cnt,dis[siz]= {0};
bool visu[siz];
int col[siz];
bool isBip(int src)
{

    memset(col,-1,sizeof col);
    col[src]=1;
    queue<int>q;
    q.push(src);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        rep(i,adj[u].size())
        {
            int v=adj[u][i];
            if(col[v]==-1)
                {col[v]=1-col[u];q.push(v);}
            else if(col[v]==col[u])
                return 0;
        }
    }
    return 1;

}
int main()
{
    int n,m;
    scad2(n,m);
    rep(i,m)
    {
        int u,v;
        cin>>u>>v;
        vec.pb(mp(u,v));
        adj[u].pb(v);
        adj[v].pb(u);
        mp1[mp(u,v)]=0;
    }
    if(m>n)
        cout<<"NO\n";
    else
    {
        if(isBip(1))
        {
            cout<<"YES\n";
            rep(i,vec.size())
            {
            cout<<max(0,col[vec[i].ff]-col[vec[i].ss]);
            }
        }
        else cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define siz 200009
#define inf 1e9+8
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll long long
#define pii pair<int,int >
#define scad(n) scanf("%d",&n)
#define scad2(m,n) scanf("%d%d",&m,&n);
#define mid (start+endd)/2
#define MOD 1000000007
#define fileout freopen("output.txt","w",stdout)
#define mem(x,i) memset(x,i,sizeof x)
#define pi acos(-1.0)
#define ff first
#define ss second
using namespace std;
vector<pii>vec;
map<pii,int> mp1;
//map<pii,bool>mp2;
bool vis[siz]= {0};
vector<int>adj[siz];
int dis[siz]= {0};
void DFS(int x)
{
    vis[x]=1;
    rep(i,adj[x].size())
    {
        int v=adj[x][i];
        // cout<<v<<' '<<x<<endl;
        if(!vis[v])
        {
            dis[v]=1-dis[x];
            mp1[mp(x,v)]=1-dis[x];
            mp1[mp(v,x)]=1-mp1[mp(x,v)];
            DFS(v);
        }
    }
}
int main()
{
    int n,m;
    scad2(n,m);
    rep(i,m)
    {
        int u,v;
        cin>>u>>v;
        vec.pb(mp(u,v));
        adj[u].pb(v);
        adj[v].pb(u);
        mp1[mp(u,v)]=0;
    }
    if(m>n)
        cout<<"NO\n";
    else
    {
        DFS(1);
        if(m==n && m%2==0)
        {
            repo(i,1,m+1)
            {
                if(adj[i].size()!=2)
                {
                    cout<<"NO\n";return 0;
                }
            }
        }
        else if(m==n && m%2)
        {
            cout<<"NO\n";return 0;
        }
        cout<<"YES\n";
        rep(i,vec.size())
        {
            cout<<mp1[vec[i]];
        }
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define siz 200009
#define inf 1e9+8
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll long long
#define pii pair<int,int >
#define scad(n) scanf("%d",&n)
#define scad2(m,n) scanf("%d%d",&m,&n);
#define mid (start+endd)/2
#define MOD 1000000007
#define fileout freopen("output.txt","w",stdout)
#define mem(x,i) memset(x,i,sizeof x)
#define pi acos(-1.0)
#define ff first
#define ss second
using namespace std;
vector<pii>vec;
map<pii,int> mp1;
//map<pii,bool>mp2;
bool vis[siz]= {0};
vector<int>adj[siz];
int dis[siz]= {0};
void DFS(int x)
{
    vis[x]=1;
    rep(i,adj[x].size())
    {
        int v=adj[x][i];
        // cout<<v<<' '<<x<<endl;
        if(!vis[v])
        {
            dis[v]=1-dis[x];
            mp1[mp(x,v)]=1-dis[x];
            mp1[mp(v,x)]=1-mp1[mp(x,v)];
            DFS(v);
        }
    }
}
int main()
{
    int n,m;
    scad2(n,m);
    rep(i,m)
    {
        int u,v;
        cin>>u>>v;
        vec.pb(mp(u,v));
        adj[u].pb(v);
        adj[v].pb(u);
        mp1[mp(u,v)]=0;
    }
    if(m>n-1)
        cout<<"NO\n";
    else
    {
        DFS(1);
        cout<<"YES\n";
        rep(i,vec.size())
        {
            cout<<mp1[vec[i]];
        }
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define siz 200009
#define inf 1e9+8
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll long long
#define pii pair<int,int >
#define scad(n) scanf("%d",&n)
#define scad2(m,n) scanf("%d%d",&m,&n);
#define mid (start+endd)/2
#define MOD 1000000007
#define fileout freopen("output.txt","w",stdout)
#define mem(x,i) memset(x,i,sizeof x)
#define pi acos(-1.0)
#define ff first
#define ss second
using namespace std;
vector<pii>vec;
map<pii,int> mp1;
bool vis[siz]= {0};
vector<int>adj[siz];
int dis[siz];
void DFS(int x)
{
    vis[x]=1;
    rep(i,adj[x].size())
    {
        int v=adj[x][i];
        if(!vis[v])
        {
            mp1[mp(x,v)]=1-dis[x];
            DFS(v);
        }
    }
}
int main()
{
    int n,m;
    scad2(n,m);
    if(m>n-1)
        cout<<"NO\n";
    else
    {
        while(m--)
        {
            int u,v;
            cin>>u>>v;
            vec.pb(mp(u,v));
            adj[u].pb(v);
            adj[v].pb(u);
            mp1[mp(u,v)]=0;
        }
        DFS(1);
        rep(i,vec.size())
        {
            cout<<mp1[vec[i]];
        }
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define siz 200009
#define inf 1e9+8
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll long long
#define pii pair<int,int >
#define scad(n) scanf("%d",&n)
#define scad2(m,n) scanf("%d%d",&m,&n);
#define mid (start+endd)/2
#define MOD 1000000007
#define fileout freopen("output.txt","w",stdout)
#define mem(x,i) memset(x,i,sizeof x)
#define pi acos(-1.0)
#define ff first
#define ss second
using namespace std;
vector<pii>vec;
map<pii,int> mp1;
//map<pii,bool>mp2;
bool vis[siz]= {0};
vector<int>adj[siz],adu[siz];
int fg=1,cnt,dis[siz]= {0};
bool visu[siz];
int col[siz];
bool isBip(int src)
{

    memset(col,-1,sizeof col);
    col[src]=1;
    queue<int>q;
    q.push(src);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        rep(i,adj[u].size())
        {
            int v=adj[u][i];
            if(col[v]==-1)
                {col[v]=1-col[u];q.push(v);}
            else if(col[v]==col[u])
                return 0;
        }
    }
    return 1;

}
int main()
{
    int n,m;
    scad2(n,m);
    rep(i,m)
    {
        int u,v;
        cin>>u>>v;
        vec.pb(mp(u,v));
        adj[u].pb(v);
        adj[v].pb(u);
        mp1[mp(u,v)]=0;
    }
    {
        if(isBip(1))
        {
            cout<<"YES\n";
            rep(i,vec.size())
            {
            cout<<max(0,col[vec[i].ff]-col[vec[i].ss]);
            }
        }
        else cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define siz 200009
#define inf 1e9+8
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll long long
#define pii pair<int,int >
#define scad(n) scanf("%d",&n)
#define scad2(m,n) scanf("%d%d",&m,&n);
#define mid (start+endd)/2
#define MOD 1000000007
#define fileout freopen("output.txt","w",stdout)
#define mem(x,i) memset(x,i,sizeof x)
#define pi acos(-1.0)
#define ff first
#define ss second
using namespace std;
vector<pii>vec;
map<pii,int> mp1;
bool vis[siz]= {0};
vector<int>adj[siz];
int dis[siz];
void DFS(int x)
{
    vis[x]=1;
    rep(i,adj[x].size())
    {
        int v=adj[x][i];
        if(!vis[v])
        {
            mp1[mp(x,v)]=1-dis[x];
            DFS(v);
        }
    }
}
int main()
{
    int n,m;
    scad2(n,m);
    if(m>n-1)
        cout<<"NO\n";
    else
    {
        while(m--)
        {
            int u,v;
            cin>>u>>v;
            vec.pb(mp(u,v));
            adj[u].pb(v);
            adj[v].pb(u);
            mp1[mp(u,v)]=0;
        }
        DFS(1);
        cout<<"YES\n";
        rep(i,vec.size())
        {
            cout<<mp1[vec[i]];
        }
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define siz 200009
#define inf 1e9+8
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define repo(i,m,n) for(int i=m;i<=n;i++)
#define ll long long
#define pii pair<int,int >
#define scad(n) scanf("%d",&n)
#define scad2(m,n) scanf("%d%d",&m,&n);
#define mid (start+endd)/2
#define MOD 1000000007
#define fileout freopen("output.txt","w",stdout)
#define mem(x,i) memset(x,i,sizeof x)
#define pi acos(-1.0)
#define ff first
#define ss second
using namespace std;
vector<pii>vec;
map<pii,int> mp1;
//map<pii,bool>mp2;
bool vis[siz]= {0};
vector<int>adj[siz];
int dis[siz]= {0};
void DFS(int x)
{
    vis[x]=1;
    rep(i,adj[x].size())
    {
        int v=adj[x][i];
        // cout<<v<<' '<<x<<endl;
        if(!vis[v])
        {
            dis[v]=1-dis[x];
            mp1[mp(x,v)]=1-dis[x];
            mp1[mp(v,x)]=1-mp1[mp(x,v)];
            DFS(v);
        }
    }
}
int main()
{
    int n,m;
    scad2(n,m);
    rep(i,m)
    {
        int u,v;
        cin>>u>>v;
        vec.pb(mp(u,v));
        adj[u].pb(v);
        adj[v].pb(u);
        mp1[mp(u,v)]=0;
    }
    if(m>n)
        cout<<"NO\n";
    else
    {
        DFS(1);
        if(m==n && m%2==0)
        {
            repo(i,1,m)
            {
                if(adj[i].size()!=2)
                {
                    cout<<"NO\n";return 0;
                }
            }
        }
        else if(m==n && m%2)
        {
            cout<<"NO\n";return 0;
        }
        cout<<"YES\n";
        rep(i,vec.size())
        {
            cout<<mp1[vec[i]];
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

map<int, int>adjace[200001];
char edge[200001], n, m, u, v, able, counter = 0;

void DFS(int place, bool color) {
    for (auto i: adjace[place]) {
        if (edge[i.second] == 2) {
            edge[i.second] = ((i.first < 0) == color) ? 1 : 0;
            DFS(abs(i.first), !color);
        }
        else if (edge[i.second] == ((i.first < 0) == color)) {
            continue;
        } else {
            able = false;
            return;
        }
    }
    counter++;
    if (counter == n)
        able = true;
}

int main() {
    while(~scanf("%d %d", &n, &m)) {
        memset(edge, 2, sizeof(edge));
        for (int i = 0; i < m; i++) {
            scanf("%d %d", &u, &v);
            adjace[u][v] = i;
            adjace[v][-u] = i;
        }
        DFS(1, true);
        if (able) {
            printf("YES\n");
            for (int i = 0; i < m; i++) {
                printf("%d", edge[i]);
            }
        } else {
            printf("NO");
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

vector<int>adjace[200001];
char vertx[200001];
int edge[200001] = {0};
bool able = true;

void DFS(int place, bool out) {
    int l = adjace[place].size(), i;
    for (int c = 0; c < l; c++) {
        i = adjace[place][c];
        if (vertx[i] == 2) {
            vertx[i] = !out;
            DFS(i, !out);
        } else if (vertx[i] == out) {
            able = false;
            return;
        }
    }
}

int main() {
    int n, m, u, v;
    memset(vertx, 2, sizeof(vertx));
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; i++) {
        scanf("%d %d", &u, &v);
        edge[i] = u;
        adjace[u].push_back(v);
        adjace[v].push_back(u);
    }
    vertx[1] = 1;
    DFS(1, true);
    if (able) {
        puts("YES");
        for (int i = 1; i <= m; i++) {
            printf("%d", vertx[edge[i]]);
        }
    } else {
        puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

struct edg {
    int from;
    int to;
};

vector<int>adjace[200001];
edg edge[200001];
char direct[200001] = {0};
bool able = true;

void DFS(int place, bool out) {
    int l = adjace[place].size(), i;
    for (int c = 0; c < l; c++) {
        i = adjace[place][c];
        if (edge[i].from == place) {
            if (!direct[i]) {
                direct[i] = out ? '1': '0';
                DFS(edge[i].to, !out);
            } else if ((direct[i] == '0') == out) {
                able = false;
                return;
            }
        } else {
            if (!direct[i]) {
                direct[i] = out ? '0': '1';
                DFS(edge[i].from, !out);
            } else if ((direct[i] == '1') == out) {
                able = false;
                return;
            }
        }
    }
}

int main() {
    int n, m, u, v;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &u, &v);
        edge[i].from = u;
        edge[i].to = v;
        adjace[u].push_back(i);
        adjace[v].push_back(i);
    }
    DFS(1, true );
    if (able) {
        direct[n+1] = '\0';
        printf("YES\n%s", direct);
    } else {
        printf("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

map<int, int>adjace[200001];
char edge[200001] = {0};
int n, m, u, v;
bool able = true;

void DFS(int place, bool color) {
    for (auto i: adjace[place]) {
        if (!edge[i.second]) {
            edge[i.second] = ((i.first < 0) == color) ? '1' : '0';
            DFS(abs(i.first), !color);
        }
        else if ((edge[i.second] == '1') != ((i.first < 0) == color)) {
            able = false;
            return;
        }
    }
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &u, &v);
        adjace[u][v] = i;
        adjace[v][-u] = i;
    }
    DFS(1, false);
    if (able) {
        edge[n+1] = '\n';
        printf("YES\n%s", edge);
    } else {
        printf("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

map<int, int>adjace[200001];
char edge[200001] = {0};
int n, m, u, v, counter = 0;
bool able;

void DFS(int place, bool color) {
    for (auto i: adjace[place]) {
        if (!edge[i.second]) {
            edge[i.second] = ((i.first < 0) == color) ? '1' : '0';
            counter++;
            if (counter == m) {
                able = true;
                return;
            }
            DFS(abs(i.first), !color);
        }
        else if ((edge[i.second] == '1')== ((i.first < 0) == color)) {
            continue;
        } else {
            able = false;
            return;
        }
    }
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &u, &v);
        adjace[u][v] = i;
        adjace[v][-u] = i;
    }
    DFS(1, false);
    if (able) {
        edge[n+1] = '\n';
        printf("YES\n%s", edge);
    } else {
        printf("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

struct edg {
    int from;
    int to;
};

vector<int>adjace[200001];
edg edge[200001];
char direct[200001] = {0};
bool able = true;

void DFS(int place, bool out) {
    int l = adjace[place].size(), i;
    for (int c = 0; c < l; c++) {
        i = adjace[place][c];
        if (edge[i].from == place) {
            if (!direct[i]) {
                direct[i] = out ? '1': '0';
                DFS(edge[i].to, !out);
            } else if ((direct[i] == '0') == out) {
                able = false;
                return;
            }
        } else {
            if (!direct[i]) {
                direct[i] = out ? '0': '1';
                DFS(edge[i].from, !out);
            } else if ((direct[i] == '1') == out) {
                able = false;
                return;
            }
        }
    }
}

int main() {
    int n, m, u, v;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &u, &v);
        edge[i].from = u;
        edge[i].to = v;
        adjace[u].push_back(i);
        adjace[v].push_back(i);
    }
    DFS(1, true );
    if (able) {
        direct[n+1] = '\0';
        puts("YES")
        puts(direct);
    } else {
        puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

map<int, int>adjace[200001];
char edge[200001];
int n, m, u, v, counter = 0;
bool able;

void DFS(int place, bool color) {
    for (auto i: adjace[place]) {
        if (edge[i.second] == 2) {
            edge[i.second] = ((i.first < 0) == color) ? 1 : 0;
            DFS(abs(i.first), !color);
        }
        else if (edge[i.second] == ((i.first < 0) == color)) {
            continue;
        } else {
            able = false;
            return;
        }
    }
    counter++;
    if (counter == n)
        able = true;
}

int main() {
    scanf("%d %d", &n, &m);
    memset(edge, 2, sizeof(edge));
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &u, &v);
        adjace[u][v] = i;
        adjace[v][-u] = i;
    }
    DFS(1, false);
    if (able) {
        printf("YES\n");
        for (int i = 0; i < m; i++) {
            printf("%d", edge[i]);
        }
    } else {
        printf("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

struct edg {
    int from;
    int to;
};

vector<int>adjace[200001];
edg edge[200001];
char direct[200001] = {0};
bool able = true;

void DFS(int place, bool out) {
    int l = adjace[place].size(), i;
    for (int c = 0; c < l; c++) {
        i = adjace[place][c];
        if (edge[i].from == place) {
            if (!direct[i]) {
                direct[i] = out ? '1': '0';
                DFS(edge[i].to, !out);
            } else if ((direct[i] == '0') == out) {
                able = false;
                return;
            }
        } else {
            if (!direct[i]) {
                direct[i] = out ? '0': '1';
                DFS(edge[i].from, !out);
            } else if ((direct[i] == '1') == out) {
                able = false;
                return;
            }
        }
    }
}

int main() {
    int n, m, u, v;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &u, &v);
        edge[i].from = u;
        edge[i].to = v;
        adjace[u].push_back(i);
        adjace[v].push_back(i);
    }
    DFS(1, true);
    if (able) {
        direct[n+1] = '\0';
        puts("YES");
        puts(direct);
    } else {
        puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

struct edg {
    int from;
    int to;
};

vector<int>adjace[200001];
edg edge[200001];
char direct[200001] = {0};
bool able = true;

void DFS(int place, bool out) {
    for (auto i: adjace[place]) {
        if (edge[i].from == place) {
            if (!direct[i]) {
                direct[i] = out ? '1': '0';
                DFS(edge[i].to, !out);
            } else if ((direct[i] == '0') == out) {
                able = false;
                return;
            }
        } else {
            if (!direct[i]) {
                direct[i] = out ? '0': '1';
                DFS(edge[i].from, !out);
            } else if ((direct[i] == '1') == out) {
                able = false;
                return;
            }
        }
    }
}

int main() {
    int n, m, u, v;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &u, &v);
        edge[i].from = u;
        edge[i].to = v;
        adjace[u].push_back(i);
        adjace[v].push_back(i);
    }
    DFS(1, true );
    if (able) {
        direct[n+1] = '\0';
        printf("YES\n%s", direct);
    } else {
        printf("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int INF=1e9+5;
typedef pair<int,int> pii;
int n,m,vis[maxn],cnt,ans[maxn],a[maxn],f,pre[maxn];
int mp[maxn];

vector<pii>e[maxn];

void init(int x)
{
    for(int i=0; i<=x; i++) e[i].clear();
    memset(vis,0,sizeof(vis));
    memset(ans,-1,sizeof(ans));
    memset(pre,-1,sizeof(pre));
}

void bfs(int s)
{
    queue<int>q;
    q.push(s);
    while(!q.empty())
    {
        int now=q.front();
        q.pop();
        ans[now]=!ans[pre[now]];
        for(int i=0; i<e[now].size(); i++)
        {
            int v=e[now][i].first;
            int u=e[now][i].second;
            //cout<<v<<" "<<u<<endl;
            if(ans[v]==-1)
            {
                ans[v]=!ans[now];
            }
            else if(ans[now]==ans[v]) f=1;
        }
    }
    return;
}

void dfs(int now,int pre,int t)
{
    ans[now]=t;
    for(int i=0; i<e[now].size(); i++)
    {
        int v=e[now][i].first;
        if(v==pre) continue;
        if(ans[v]==-1) dfs(v,now,!t);
        else if(ans[v]==ans[now]) f=1;
    }
    return;
}

int main()
{
    cin>>n>>m;
    init(n);
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin>>x>>y;
        a[i]=x;
        e[x].push_back(make_pair(y,-1));
        e[y].push_back(make_pair(x,-1));
    }
    ans[1]=1;
    bfs(1);
    //dfs(1,-1,0);
    if(f!=1)
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=m; i++)
            cout<<ans[a[i]];
        cout<<endl;
    }
    else
        cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
bool nv[100][100];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    nv[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')    vis[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    nv[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')
                vis2[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
    int i,j,c=0,c1=0,c2=0;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   c++;
            if(vis[i][j])   c1++;
            if(vis2[i][j])  c2++;
        }
    }
    if(c)   return true;
//    if(c==c1&&c==c2)    return true;
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start, coordinate destination)
{
    memset(vis,false,sizeof(vis));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        if(w.x==destination.x && w.y==destination.y)  return true;
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(vis[h.x][h.y])   continue;
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(s[h.x][h.y]=='#')    continue;
            q.push(h);
            vis[h.x][h.y]=true;
        }
    }
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        if(bfs(p[0],p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
bool nv[100][100];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')    vis[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')
                vis2[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
    int i,j,c=0,c1=0,c2=0;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   c++;
            if(vis[i][j])   c1++;
            if(vis2[i][j])  c2++;
        }
    }
    if(c)   return true;
//    if(c==c1&&c==c2)    return true;
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
bool nv[100][100];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')    vis[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis2[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')
                vis2[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
    int i,j,c=0;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   c++;
        }
    }
    if(c>=2)    return true;
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
bool nv[100][100];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]=='.')    vis[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    memset(nv,false,sizeof(nv));
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis2[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]=='.')
                vis2[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
    int i,j,c=0,c1=0,c2=0;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   c++;
            //if(vis[i][j])   c1++;
            //if(vis2[i][j])  c2++;
        }
    }
    if(c)   return true;
//    if(c&&c==c1&&c==c2)    return true;
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                    s[i][j]='.';
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
bool nv[100][100];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')    vis[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')
                vis2[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
    int i,j,c=0,c1=0,c2=0;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   c++;
            if(vis[i][j])   c1++;
            if(vis2[i][j])  c2++;
        }
    }
//    cout<<c<<' '<<c1<<' '<<c2<<endl;
    if(c)   return true;
//    if(c==c1&&c==c2)    return true;
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(vis[h.x][h.y])   continue;
            if(s[h.x][h.y]=='#')    continue;
            q.push(h);
            vis[h.x][h.y]=true;
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis2[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(vis2[h.x][h.y])   continue;
            if(s[h.x][h.y]=='#')    continue;
            q.push(h);
            vis2[h.x][h.y]=true;
        }
    }
    int i,j;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   return true;
        }
    }
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
bool nv[100][100];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')    vis[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')
                vis2[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
    int i,j,c=0,c1=0,c2=0;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   c++;
            if(vis[i][j])   c1++;
            if(vis2[i][j])  c2++;
        }
    }
//    cout<<c<<' '<<c1<<' '<<c2<<endl;
    if(c>2)   return true;
//    if(c==c1&&c==c2)    return true;
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
bool nv[100][100];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')    vis[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    memset(nv,false,sizeof(nv));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis2[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]!='#')
                vis2[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
        }
    }
    int i,j,c=0;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   c++;
        }
    }
    if(c)    return true;
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
vector<coordinate>moves[100];
bool vis[200][200];
bool nv[100][100];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    for(int i=0;i<100;i++)  moves[i].clear();
    memset(vis,false,sizeof(vis));
    memset(nv,false,sizeof(nv));
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis[start.x][start.y]=true;
    int k = 1;
    moves[k++].push_back(start);
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]=='.')    vis[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
            moves[k].push_back(h);
        }
        k++;
    }
}
vector<coordinate>moves2[100];
bool vis2[200][200];
bool bfs2(coordinate start)
{
    for(int i=0;i<100;i++)  moves2[i].clear();
    memset(vis2,false,sizeof(vis2));
    memset(nv,false,sizeof(nv));
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis2[start.x][start.y]=true;
    int k = 1;
    moves2[k++].push_back(start);
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(nv[h.x][h.y])   continue;
            if(s[h.x][h.y]=='.')    vis2[h.x][h.y]=true;
            nv[h.x][h.y]=true;
            q.push(h);
            moves2[k].push_back(h);
        }
        k++;
    }
    int i,j,u,v,sz1,sz2;
    for(u=1;u<k;u++){
        sz1=moves[u].size();
        for(i=0;i<sz1;i++){
            sz2=moves2[u].size();
            for(j=0;j<sz2;j++){
                if(moves[u][i].x==moves2[u][j].x&&moves[u][i].y==moves2[u][j].y){
                    return true;
                }
            }
        }
    }
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                    s[i][j]='.';
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a)  memset(a,0,sizeof(a))
#define __set(a)  memset(a,-1,sizeof(a))
#define ll long long
#define ull  unsigned long long
#define gc getchar
int read_int() {
    char c = gc();
    int flag = 0;
    if(c=='-')  flag = 1;
    while(c<'0' || c>'9') c = gc();
    int ret = 0;
    while(c>='0' && c<='9') {
        ret = 10 * ret + c - 48;
        c = gc();
    }
    if(flag)    return -ret;
    return ret;
}
#define si(a)    (a=read_int())
#define sii(a,b)    (si(a),si(b))
#define rep(i,a,b)  for(i=a;i<b;i++)
#define MAX 1000003
#define MOD 1000000007
int n,i,j,k;
string s[10];
struct coordinate{
    int x;
    int y;
}p[2];
bool vis[200][200];
int dx[]={2,2,-2,-2};
int dy[]={2,-2,2,-2};
bool bfs(coordinate start)
{
    memset(vis,false,sizeof(vis));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(vis[h.x][h.y])   continue;
            if(s[h.x][h.y]=='#')    continue;
            q.push(h);
            vis[h.x][h.y]=true;
        }
    }
}
bool vis2[200][200];
bool bfs2(coordinate start)
{
    memset(vis2,false,sizeof(vis2));
    int k;
    coordinate w,h;
    bool r=false;
    queue<coordinate>q;
    q.push(start);
    vis2[start.x][start.y]=true;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            h.x=w.x+dx[i];
            h.y=w.y+dy[i];
            if(h.x<0||h.x>=8||h.y<0||h.y>=8)    continue;
            if(vis2[h.x][h.y])   continue;
            if(s[h.x][h.y]=='#')    continue;
            q.push(h);
            vis2[h.x][h.y]=true;
        }
    }
    int i,j,c=0;
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(vis[i][j]&&vis2[i][j])   c++;
        }
    }
    if(c>=2)    return true;
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        for(i=0;i<8;i++)    s[i].clear();
        for(i=0;i<8;i++){
            cin>>s[i];
        }
        k=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(s[i][j]=='K'){
                    p[k].x=i;
                    p[k++].y=j;
                }
            }
        }
        bfs(p[0]);
        if(bfs2(p[1]))  cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <stdio.h>

#define maxn 200
#define inf 1000000001

using namespace std;

int i, j, n, m, l, r, t;
int cnt[maxn][maxn], cnt2[maxn][maxn];
bool used[maxn][maxn], used2[maxn][maxn];
char a[maxn][maxn];
int x[maxn * maxn], y[maxn * maxn];
int u, v, u2, v2, tu, tv;
bool first;

bool ok1(int u, int v)
{
	// right up
	for (int j = v + 1; j <= v + 2; j++)
		if (a[u][j] == '#')
			return false;
	for (int i = u - 1; i <= u - 2; i++)
		if (a[i][v + 2] == '#')
			return false;
	return true;
}

bool ok2(int u, int v)
{
	// right down

	for (int j = v + 1; j <= v + 2; j++)
		if (a[u][j] == '#')
			return false;
	for (int i =u + 1; i <= u + 2; i++)
		if (a[u][v + 2] == '#')
			return false;
	return true;
}

bool ok3(int u, int v)
{
	//left up
	for (int j = v - 1; j <= v - 2; j++)
		if (a[u][j] == '#')
			return false;
	for (int i = u - 1; i <= u - 2; i++)
		if (a[i][v - 2])
			return false;
	return true;
}

bool ok4(int u, int v)
{
	//left down
	for (int j = v - 1; j <= v - 2; j++)
		if (a[u][j] == '#')
			return false;
	for (int i = u + 1; i <= u + 2; i++)
		if (a[i][v - 2])
			return false;
	return true;
}

bool valid(int u, int v)
{
    if (u && v && u <= n && v <= n)
        return true;
    return false;
}

void bfs(int u, int v)
{
	l = r = 1;
	int u2, v2;
	x[l] = u;
	used[u][v] = true;
	y[l] = v;
	while (l <= r)
	{
		u = x[l];
		v = y[l];

		if (ok1(u, v) && !used[u - 2][v + 2] && valid(u - 2, v + 2))
		{
			tu = u - 2;
			tv = v + 2;
			r++;
			x[r] = tu;
			y[r] = tv;
			used[tu][tv] = true;
			cnt[tu][tv] = cnt[u][v] + 1;
		}

		if (ok2(u, v) && !used[u + 2][v + 2] && valid(u + 2, v + 2))
		{
			tu = u + 2;
			tv = v + 2;
			r++;
			x[r] = tu;
			y[r] = tv;

			cnt[tu][tv] = cnt[u][v] + 1;
			used[tu][tv] = true;
		}

		if (ok3(u, v) && !used[u - 2][v - 2] && valid(u - 2, v - 2))
		{
			tu = u - 2;
			tv = v - 2;
			r++;
			x[r] = tu;
			y[r] = tv;

			cnt[tu][tv] = cnt[u][v] + 1;
			used[tu][tv] = true;
		}

		if (ok4(u, v) && !used[u + 2][v - 2] && valid(u + 2, v - 2))
		{
			tu = u + 2;
			tv = v - 2;
			r++;
			x[r] = tu;
			y[r] = tv;

			cnt[tu][tv] = cnt[u][v] + 1;
			used[tu][tv] = true;
		}

		l++;
	}

}

void bfs2(int u, int v)
{
	l = r = 1;
	x[l] = u;
	y[l] = v;
	used2[u][v] = true;
	while (l <= r)
	{
		u = x[l];
		v = y[l];

		if (ok1(u, v) && !used2[u - 2][v + 2] && valid(u - 2, v + 2))
		{
			tu = u - 2;
			tv = v + 2;

			r++;
			x[r] = tu;
			y[r] = tv;

			cnt2[tu][tv] = cnt2[u][v] + 1;
			used2[tu][tv] = true;
		}

		if (ok2(u, v) && !used2[u + 2][v + 2] && valid(u + 2, v + 2))
		{
			tu = u + 2;
			tv = v + 2;
			r++;
			x[r] = tu;
			y[r] = tv;
			cnt2[tu][tv] = cnt2[u][v] + 1;
			used2[tu][tv] = true;
		}

		if (ok3(u, v) && !used2[u - 2][v - 2] && valid(u - 2, v - 2))
		{
			tu = u - 2;
			tv = v - 2;
			r++;
			x[r] = tu;
			y[r] = tv;
			cnt2[tu][tv] = cnt2[u][v] + 1;
			used2[tu][tv] = true;
		}

		if (ok4(u, v) && !used2[u + 2][v -2] && valid(u + 2, v - 2))
		{
			tu = u + 2;
			tv = v - 2;
			r++;
			x[r] = tu;
			y[r] = tv;
			cnt2[tu][tv] = cnt2[u][v] + 1;
			used2[tu][tv] = true;
		}

		l++;
	}
}

void cl()
{
	for (int i = 1; i <= n; i++)
	 	a[0][i] = '#', a[n + 1][i] = '#', a[i][0] = '#', a[i][n + 1] = '#';

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			cnt[i][j] = cnt2[i][j]= 0;
			used[i][j] = used2[i][j] = false;
		}
}

int main()
{

	//freopen("input.txt", "r", stdin);

	scanf("%d\n", &t);

	while (t--)
	{
		n = 8;
		first = false;
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				scanf("%c", &a[i][j]);
				if (a[i][j] == 'K' && !first)
				{
					u = i;
					v = j;
					first = true;
				}
				else
				if (first && a[i][j] == 'K')
					u2 = i, v2 = j;
			}
			scanf("\n");
		}

		cl();

		bfs(u, v);

		bfs2(u2, v2);

        string ans = "NO";
		for (i = 1; i <= n; i++)
            for (j = 1; j <= n; j++)
                if (cnt[i][j]  && cnt[i][j] == cnt2[i][j])
                    ans = "YES";
        cout<<ans<<endl;

	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <stdio.h>

#define maxn 200
#define inf 1000000001

using namespace std;

int i, j, n, m, l, r, t;
int cnt[maxn][maxn], cnt2[maxn][maxn];
bool used[maxn][maxn], used2[maxn][maxn];
char a[maxn][maxn];
int x[maxn * maxn], y[maxn * maxn];
int u, v, u2, v2, tu, tv;
bool first;

bool ok1(int u, int v)
{
	// right up
	for (int j = v + 1; j <= v + 2; j++)
		if (a[u][j] == '#' || a[u][j] == 'K')
			return false;
	for (int i = u - 1; i <= u - 2; i++)
		if (a[i][v + 2] == '#' || a[i][v + 2] == 'K')
			return false;
	return true;
}

bool ok2(int u, int v)
{
	// right down

	for (int j = v + 1; j <= v + 2; j++)
		if (a[u][j] == '#' || a[u][j] == 'K')
			return false;
	for (int i =u + 1; i <= u + 2; i++)
		if (a[u][v + 2] == '#' || a[u][v + 2] == 'K')
			return false;
	return true;
}

bool ok3(int u, int v)
{
	//left up
	for (int j = v - 1; j <= v - 2; j++)
		if (a[u][j] == '#' || a[u][j] == 'K')
			return false;
	for (int i = u - 1; i <= u - 2; i++)
		if (a[i][v - 2] || a[i][v - 2] == 'K')
			return false;
	return true;
}

bool ok4(int u, int v)
{
	//left down
	for (int j = v - 1; j <= v - 2; j++)
		if (a[u][j] == '#' || a[u][j] == 'K')
			return false;
	for (int i = u + 1; i <= u + 2; i++)
		if (a[i][v - 2] == '#' || a[i][v - 2] == '#')
			return false;
	return true;
}

bool valid(int u, int v)
{
    if (u > 0 && v > 0 && u <= n && v <= n)
        return true;
    return false;
}

void bfs(int u, int v)
{
	l = r = 1;
	int u2, v2;
	x[l] = u;
	used[u][v] = true;
	y[l] = v;
	while (l <= r)
	{
		u = x[l];
		v = y[l];

		if (ok1(u, v) && !used[u - 2][v + 2] && valid(u - 2, v + 2))
		{
			tu = u - 2;
			tv = v + 2;
			r++;
			x[r] = tu;
			y[r] = tv;
			used[tu][tv] = true;
			cnt[tu][tv] = cnt[u][v] + 1;
		}

		if (ok2(u, v) && !used[u + 2][v + 2] && valid(u + 2, v + 2))
		{
			tu = u + 2;
			tv = v + 2;
			r++;
			x[r] = tu;
			y[r] = tv;

			cnt[tu][tv] = cnt[u][v] + 1;
			used[tu][tv] = true;
		}

		if (ok3(u, v) && !used[u - 2][v - 2] && valid(u - 2, v - 2))
		{
			tu = u - 2;
			tv = v - 2;
			r++;
			x[r] = tu;
			y[r] = tv;

			cnt[tu][tv] = cnt[u][v] + 1;
			used[tu][tv] = true;
		}

		if (ok4(u, v) && !used[u + 2][v - 2] && valid(u + 2, v - 2))
		{
			tu = u + 2;
			tv = v - 2;
			r++;
			x[r] = tu;
			y[r] = tv;

			cnt[tu][tv] = cnt[u][v] + 1;
			used[tu][tv] = true;
		}

		l++;
	}

}

void bfs2(int u, int v)
{
	l = r = 1;
	x[l] = u;
	y[l] = v;
	used2[u][v] = true;
	while (l <= r)
	{
		u = x[l];
		v = y[l];

		if (ok1(u, v) && !used2[u - 2][v + 2] && valid(u - 2, v + 2))
		{
			tu = u - 2;
			tv = v + 2;

			r++;
			x[r] = tu;
			y[r] = tv;

			cnt2[tu][tv] = cnt2[u][v] + 1;
			used2[tu][tv] = true;
		}

		if (ok2(u, v) && !used2[u + 2][v + 2] && valid(u + 2, v + 2))
		{
			tu = u + 2;
			tv = v + 2;
			r++;
			x[r] = tu;
			y[r] = tv;
			cnt2[tu][tv] = cnt2[u][v] + 1;
			used2[tu][tv] = true;
		}

		if (ok3(u, v) && !used2[u - 2][v - 2] && valid(u - 2, v - 2))
		{
			tu = u - 2;
			tv = v - 2;
			r++;
			x[r] = tu;
			y[r] = tv;
			cnt2[tu][tv] = cnt2[u][v] + 1;
			used2[tu][tv] = true;
		}

		if (ok4(u, v) && !used2[u + 2][v -2] && valid(u + 2, v - 2))
		{
			tu = u + 2;
			tv = v - 2;
			r++;
			x[r] = tu;
			y[r] = tv;
			cnt2[tu][tv] = cnt2[u][v] + 1;
			used2[tu][tv] = true;
		}

		l++;
	}
}

void cl()
{
	for (int i = 1; i <= n; i++)
	 	a[0][i] = '#', a[n + 1][i] = '#', a[i][0] = '#', a[i][n + 1] = '#';

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			cnt[i][j] = cnt2[i][j]= 0;
			used[i][j] = used2[i][j] = false;
		}
}

int main()
{

	//freopen("input.txt", "r", stdin);

	scanf("%d\n", &t);

	while (t--)
	{
		n = 8;
		first = false;
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				scanf("%c", &a[i][j]);
				if (a[i][j] == 'K' && !first)
				{
					u = i;
					v = j;
					first = true;
				}
				else
				if (first && a[i][j] == 'K')
					u2 = i, v2 = j;
			}
			scanf("\n");
		}

		cl();

		bfs(u, v);

		bfs2(u2, v2);

        string ans = "NO";
		for (i = 1; i <= n; i++)
            for (j = 1; j <= n; j++)
                if (cnt[i][j]  && cnt[i][j] == cnt2[i][j])
                    ans = "YES";
        cout<<ans<<endl;

	}

	return 0;
}