import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

int lsb(int x) {
    int c = 0;
    while (x > 0) {
        x >>= 1;
        c++;
    }
    return c;
}
 
void main() {
    int N, M;
    int[][] G;
    int[][] S;
    int init;

    bool input() {
        scanf("%d %d\n", &N, &M);
        if (N == 0 && M == 0) return false;
        G = new int[][N];
        S = new int[][N];
        foreach (i; 0 .. M) {
            int s, t; scanf("%d %d\n", &s, &t);
            s--; t--;
            G[s] ~= t;
            G[t] ~= s;
        }
        init = 0;
        foreach (i; 0 .. N) {
            int s; scanf("%d", &s);
            init |= (s << i);
        }
        foreach (i; 0 .. N) {
            int k; scanf("%d\n", &k);
            foreach (j; 0 .. k) {
                int r; scanf("%d", &r);
                r--;
                S[i] ~= r;
            }
            S[i].sort;
        }
        return true;
    }

    void solve() {
        struct P {
            int v, bit;
        }
        const X = P(-1, -1);
        auto prev = new P[][](N, 1 << N);
        bool bfs() {
            foreach (i; 0 .. N) prev[i][] = X;
            DList!P Q;
            Q.insert(P(0, init));
            while (!Q.empty) {
                P p = Q.front; Q.removeFront;
                if (p.v == N - 1 && p.bit == (1 << (N - 1))) {
                    return true;
                }
                foreach (v; G[p.v]) {
                    if (prev[v][p.bit] != X) continue;
                    if (p.bit & (1 << v)) {
                        prev[v][p.bit] = p;
                        Q.insert(P(v, p.bit));
                    }
                }
                foreach (v; S[p.v]) {
                    int bit;
                    if (p.bit & (1 << v)) {
                        bit = p.bit - (1 << v);
                    } else {
                        bit = p.bit + (1 << v);
                    }
                    if (prev[p.v][bit] != X) continue;
                    prev[p.v][bit] = p;
                    Q.insert(P(p.v, bit));
                }
            }
            return false;
        }
        if (bfs) {
            int v = N - 1, bit = 1 << (N - 1);
            string[] path;
            while (v != 0 || bit != init) {
                int v1 = prev[v][bit].v;
                int bit1 = prev[v][bit].bit;
                if (v == v1) {
                    string fstr = "Switch " ~ (bit > bit1 ? "on" : "off") ~ " room %d.";
                    path ~= format(fstr, lsb(bit ^ prev[v][bit].bit));
                } else {
                    path ~= format("Move to room %d.", v + 1);
                }
                //writefln("%d %b -> %d %b", v1, bit1, v, bit);
                v = v1;
                bit = bit1;
            }
            writefln("You can go home in %d steps.", path.length);
            path.reverse;
            foreach (p; path) {
                writeln(p);
            }
        } else {
            bool r() {
                foreach (i; 0 .. (1 << N)) {
                    if (prev[N - 1][i] != X) {
                        return true;
                    }
                }
                return false;
            }
            writeln( r ? "You can not switch off all lights." : "Help me!" );
        }
    }

    while (input) {
        solve;
    }
}