#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 5;
vector<int> G[MX];
bool dp[MX][2], mark[MX][2];
void init(int n){
for(int i = 0; i < n; G[i].clear(), i++);
}
bool solve(int node, int player){
if(mark[node][player]) return dp[node][player];
int next = 0;
bool Ans = false;
for(int i = 0; i < G[node].size(); i++){
next++;
Ans |= solve(G[node][i], 1 - player);
}
mark[node][player] = true;
if(!next){
if(player) return dp[node][player] = true;
}
return dp[node][player] = Ans;
}
int main() {
int t, n, m, st, u, v;
scanf("%d", &t);
for(int i = 1; i <= t; i++){
scanf("%d %d %d", &n, &m, &st);
init(n);
for(int j = 0; j < m; j++){
scanf("%d %d", &u, &v); u--, v--;
G[u].push_back(v);
}
memset(dp, false, sizeof(dp));
memset(mark, false, sizeof(mark));
bool Ans = solve(st - 1, 0);
Ans ? printf("Case %d: Yes\n", i) : printf("Case %d: No\n", i);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTVggPSAxZTUgKyA1Owp2ZWN0b3I8aW50PiBHW01YXTsKYm9vbCBkcFtNWF1bMl0sIG1hcmtbTVhdWzJdOwoKdm9pZCBpbml0KGludCBuKXsKCWZvcihpbnQgaSA9IDA7IGkgPCBuOyBHW2ldLmNsZWFyKCksIGkrKyk7Cn0KCmJvb2wgc29sdmUoaW50IG5vZGUsIGludCBwbGF5ZXIpewoJaWYobWFya1tub2RlXVtwbGF5ZXJdKSByZXR1cm4gZHBbbm9kZV1bcGxheWVyXTsKCWludCBuZXh0ID0gMDsKCWJvb2wgQW5zID0gZmFsc2U7CgkKCWZvcihpbnQgaSA9IDA7IGkgPCBHW25vZGVdLnNpemUoKTsgaSsrKXsKCQluZXh0Kys7CgkJQW5zIHw9IHNvbHZlKEdbbm9kZV1baV0sIDEgLSBwbGF5ZXIpOwoJfQoJCgltYXJrW25vZGVdW3BsYXllcl0gPSB0cnVlOwoJaWYoIW5leH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