#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int maxn = 1e5 + 5;
int n, m;
int t[maxn];
vector<int> gid[maxn];
vector<int> grp[maxn];
ll dis1[maxn], dis2[maxn];
void dijkstra(int S, ll *dis)
{
    struct heap_node
    {
        int u;
        ll d;
        OPL(heap_node, rhs) { return d > rhs.d; }
    };
    priority_queue<heap_node> H;
    H.push({S, dis[S] = 0});
    for (heap_node cur; !H.empty(); H.pop())
        for (int g : gid[(cur = H.top()).u])
            for (int to : grp[g])
                if (dis[to] > dis[cur.u] + t[g])
                    H.push({to, dis[to] = dis[cur.u] + t[g]});
}
int main()
{

    int T;
    cin >> T;
    for (int _ = 1; _ <= T; _++)
    {
        scanf("%d%d", &n, &m);
        memset(dis1, 0x3f, sizeof(ll) * (n + 2));
        memset(dis2, 0x3f, sizeof(ll) * (n + 2));
        for (int i = 1; i <= n; i++)
            gid[i].clear();
        for (int i = 0, cnt; i < m; i++)
        {
            grp[i].clear();
            scanf("%d%d", t + i, &cnt);
            for (int j = 0, x; j < cnt; j++)
            {
                scanf("%d", &x);
                gid[x].push_back(i);
                grp[i].push_back(x);
            }
        }
        dijkstra(1, dis1);
        dijkstra(n, dis2);
        ll mx = LLONG_MAX;
        for (int i = 1; i <= n; i++)
            mx = min(mx, max(dis1[i], dis2[i]));
        IFD
        {
            for (int i = 1; i <= n; i++)
                printf("%lld%c", dis1[i], " \n"[i == n]);
            for (int i = 1; i <= n; i++)
                printf("%lld%c", dis2[i], " \n"[i == n]);
        }
        printf("Case #%d: ", _);
        ll inf = *dis1 >> 1;
        if (mx >= inf)
            puts("Evil John");
        else
        {
            printf("%lld\n", mx);
            for (int i = 1; i <= n; i++)
                if (mx == max(dis1[i], dis2[i]))
                    printf("%d ", i);
            putchar('\n');
        }
    }
    return 0;
}