import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
loop:
    while(true) {
        int n, m;
        readlnTo(n, m);
        if(n == 0 && m == 0) {
            return;
        }
        auto e = new int[][](n);
        foreach(i; iota(m)) {
            int s, t;
            readlnTo(s, t);
            --s;
            --t;
            e[s] ~= t;
            e[t] ~= s;
        }
        auto l = readInts();
        int[][] sw;
        foreach(i; iota(n)) {
            auto tmp = readInts().map!(a => a-1).array;
            sw ~= tmp[1..$].sort().array;
        }

        alias Tuple!(int, "room", int, "light") State;

        int bl;
        foreach(i; iota(n)) {
            bl |= l[i] << i;
        }
        const auto begin = State(0, bl);
        const auto goal = State(n-1, 1 << (n-1));
        bool[State] used;
        used[begin] = true;
        State[State] prev;
        int[State] step;
        step[begin] = 0;
        auto q = DList!State(begin);
        while(!q.empty()) {
            auto f = q.front();
            q.removeFront();
            if(f == goal) {
                break;
            }
            foreach(i; sw[f.room]) {
                auto next = State(f.room, f.light ^ (1 << i));
                if(next in used) {
                    continue;
                }
                if((next.light & (1 << next.room)) == 0) {
                    continue;
                }
                used[next] = true;
                prev[next] = f;
                step[next] = step[f] + 1;
                q.insertBack(next);
            }
            foreach(i; e[f.room]) {
                auto next = State(i, f.light);
                if(next in used) {
                    continue;
                }
                if((next.light & (1 << next.room)) == 0) {
                    continue;
                }
                used[next] = true;
                prev[next] = f;
                step[next] = step[f] + 1;
                q.insertBack(next);
            }
        }
        if(goal in used) {
            string backTrace(State s) {
                if(s == begin) {
                    return "";
                } else {
                    auto p = prev[s];
                    if(s.room == p.room) {
                        if(s.light > p.light) {
                            int n;
                            uint r = (s.light - p.light).to!uint;
                            while(r > 0) {
                                ++n;
                                r >>= 1;
                            }
                            return backTrace(p) ~ "Switch on room " ~ n.to!string ~ ".\n";
                        } else {
                            int n;
                            uint r = (p.light - s.light).to!uint;
                            while(r > 0) {
                                ++n;
                                r >>= 1;
                            }
                            return backTrace(p) ~ "Switch off room " ~ n.to!string ~ ".\n";
                        }
                    } else {
                        return backTrace(p) ~ "Move to room " ~ (s.room + 1).to!string ~ ".\n";
                    }
                }
            };
            writefln("You can go home in %d steps.", step[goal]);
            write(backTrace(goal));
            continue loop;
        }
        foreach(i; iota(1, 1<<n)) {
            if(State(n-1, i) in used) {
                writeln("You can not switch off all lights.");
                continue loop;
            }
        }
        writeln("Help me!");
    }
}