#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

class Act
{
public:
	int m,p,r,tn;
	Act(int m, int p, int r, int tn)
	:m(m),p(p),r(r),tn(tn)
	{}
};

class Dct
{
public:
	int p,sp;
	vector<Act> ac;
	Dct(int p, int sp)
	:p(p),sp(sp)
	{}
	
	Dct(int np, bool f, Dct& d)
	:sp(d.sp),ac(d.ac)
	{
		if(f)
		{
			p=d.p;
			if(sp&(1<<np)) ac.push_back(Act(0,np+1, d.p, np));
			else ac.push_back(Act(1,np+1, d.p, np));
			
			if(sp&(1<<np)) sp-=(1<<np);
			else 		   sp|=(1<<np);
		}
		else
		{
			p=np;
			ac.push_back(Act(2,np+1, -1, -1));
		}
	}
};

class Room
{
public:
	vector<int> to,sw;
};

int main()
{
	int N,M,K;
	while(scanf("%d%d", &N,&M),(N||M))
	{
		int sp=0;
		bool h[32768][15]={0};
		Room rm[15];
		
		while(M--)
		{
			int s,t;
			scanf("%d%d", &s,&t);
			s--;t--;
			rm[s].to.push_back(t);
			rm[t].to.push_back(s);
		}
		
		for(int i=0; i<N; i++)
		{
			int t;
			scanf("%d", &t);
			sp|=(t<<i);
		}
			
		for(int i=0; i<N; i++)
		{
			scanf("%d", &K);
			while(K--)
			{
				int t;
				scanf("%d", &t);
				t--;
				rm[i].sw.push_back(t);
			}
			
			if(!rm[i].sw.empty()) sort(rm[i].sw.begin(), rm[i].sw.end());
		}
		
		queue<Dct> q;
		q.push(Dct(0,sp));
		
		int st=-1;
		while(!q.empty())
		{
			Dct d=q.front(); q.pop();
			
			if(d.p==N-1)
			{
				if(d.sp==(1<<(N-1)))
				{
					st=1;
					printf("You can go home in %d steps.\n", d.ac.size());
					for(int i=0; i<d.ac.size(); i++)
					{
						if(d.ac[i].m==2) printf("Move to room %d.\n", d.ac[i].p);
						else	printf("Switch %s room %d.\n", (d.ac[i].m==1?"on":"off"), d.ac[i].p);
					}
					break;
				}
				else st=0;
			}
			
			for(int i=0; i<rm[d.p].to.size(); i++)
			{
				int next=rm[d.p].to[i];
				if(!(d.sp&(1<<next))) continue;
				
				if(h[d.sp][next]) continue;
				h[d.sp][next]=1;
				
				q.push(Dct(next, 0, d));
			}
			
			for(int i=0; i<rm[d.p].sw.size(); i++)
			{
				int next=rm[d.p].sw[i];
				if(d.p==next) continue;
				if(!d.ac.empty())
				{
					int t=d.ac[d.ac.size()-1].tn;
					if(t!=-1&&t>=next) continue;
				}
				
				int tsp=d.sp;
				if(tsp&(1<<next)) tsp-=(1<<next);
				else 			  tsp|=(1<<next);
				
				if(h[tsp][d.p]) continue;
				h[tsp][d.p]=1;
				
				q.push(Dct(next, 1, d));
			}
		}
		
		if(st==0) puts("You can not switch off all lights.");
		if(st==-1) puts("Help me!");
	}
}