1 #pragma comment(linker, "/STACK:1024000000,1024000000")
2 #include<iostream>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<math.h>
7 #include<algorithm>
8 #include<queue>
9 #include<set>
10 #include<bitset>
11 #include<map>
12 #include<vector>
13 #include<stdlib.h>
14 #include <stack>
15 using namespace std;
16 #define PI acos(-1.0)
17 #define max(a,b) (a) > (b) ? (a) : (b)
18 #define min(a,b) (a) < (b) ? (a) : (b)
19 #define ll long long
20 #define eps 1e-10
21 #define MOD 1000000007
22 #define N 100006
23 #define inf 1e12
24 int n,m,s;
25 vector<int> g[N];
26 int color[N];
27 bool dfs(int u,int c){
28 color[u]=c;
29 for(int i=0;i<g[u].size();i++){
30 int next=g[u][i];
31 if(color[next]!=-1){
32 if(color[next]==c){
33 return true;
34 }
35 continue;
36 }
37 if(dfs(next,!c)) return true;
38 }
39 return false;
40 }
41 int main()
42 {
43 int t;
44 int ac=0;
45 scanf("%d",&t);
46 while(t--){
47 for(int i=0;i<N;i++){
48 g[i].clear();
49 }
50 scanf("%d%d%d",&n,&m,&s);
51 for(int i=0;i<m;i++){
52 int u,v;
53 scanf("%d%d",&u,&v);
54 g[u].push_back(v);
55 g[v].push_back(u);
56 }
57 memset(color,-1,sizeof(color));
58 printf("Case %d: ",++ac);
59 if(dfs(s,0)){
60 printf("YES\n");
61 }else{
62 printf("NO\n");
63 }
64 }
65 return 0;
66 }