#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int testcase = 0;
cin >> testcase;
while (testcase--) {
int n, m;
cin >> n >> m;
vector<vector<int>> G(n + 1); // 1-indexed graph
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
if (x <= n && y <= n) { // Check if both nodes are within valid range
G[x].push_back(y);
G[y].push_back(x); // Undirected graph
}
}
int source;
cin >> source;
queue<int> q;
q.push(source);
vector<int> used(n + 1, 0); // Visited nodes
used[source] = 1;
vector<int> lvl(n + 1, -1); // Level array, -1 means unvisited
lvl[source] = 0; // Source node has level 0
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto x : G[v]) {
if (used[x] == 0) {
q.push(x);
used[x] = 1;
lvl[x] = lvl[v] + 1; // Distance from source
}
}
}
// Print the answers for each node (1 to n)
for (int i = 1; i <= n; i++) {
if (used[i] == 0) {
cout << "No ";
} else {
cout << "Yes ";
}
}
cout << "\n"; // Newline after each test case
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGxsIGxvbmcgbG9uZyBpbnQKI2RlZmluZSBNT0QgMTAwMDAwMDAwNwoKaW50IG1haW4oKXsKI2lmbmRlZiBPTkxJTkVfSlVER0UKICAgIGZyZW9wZW4oImlucHV0LnR4dCIsICJyIiwgc3RkaW4pOwogICAgZnJlb3Blbigib3V0cHV0LnR4dCIsICJ3Iiwgc3Rkb3V0KTsKI2VuZGlmCgogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOyBjb3V0LnRpZShOVUxMKTsKCiAgICBpbnQgdGVzdGNhc2UgPSAwOwogICAgY2luID4+IHRlc3RjYXNlOwogICAgCiAgICB3aGlsZSAodGVzdGNhc2UtLSkgewogICAgICAgIGludCBuLCBtOwogICAgICAgIGNpbiA+PiBuID4+IG07CiAgICAgICAgCiAgICAgICAgdmVjdG9yPHZlY3RvcjxpbnQ+PiBHKG4gKyAxKTsgIC8vIDEtaW5kZXhlZCBncmFwaAogICAgICAgIAogICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG07IGkrKykgewogICAgICAgICAgICBpbnQgeCwgeTsKICAgICAgICAgICAgY2luID4+IHggPj4geTsKICAgICAgICAgICAgaWYgKHggPD0gbiAmJiB5IDw9IG4pIHsgIC8vIENoZWNrIGlmIGJvdGggbm9kZXMgYXJlIHdpdGhpbiB2YWxpZCByYW5nZQogICAgICAgICAgICAgICAgR1t4XS5wdXNoX2JhY2soeSk7CiAgICAgICAgICAgICAgICBHW3ldLnB1c2hfYmFjayh4KTsgIC8vIFVuZGlyZWN0ZWQgZ3JhcGgKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBpbnQgc291cmNlOwogICAgICAgIGNpbiA+PiBzb3VyY2U7CiAgICAgICAgCiAgICAgICAgcXVldWU8aW50PiBxOwogICAgICAgIHEucHVzaChzb3VyY2UpOwogICAgICAgIAogICAgICAgIHZlY3RvcjxpbnQ+IHVzZWQobiArIDEsIDApOyAgLy8gVmlzaXRlZCBub2RlcwogICAgICAgIHVzZWRbc291cmNlXSA9IDE7CiAgICAgICAgCiAgICAgICAgdmVjdG9yPGludD4gbHZsKG4gKyAxLCAtMSk7ICAvLyBMZXZlbCBhcnJheSwgLTEgbWVhbnMgdW52aXNpdGVkCiAgICAgICAgbHZsW3NvdXJjZV0gPSAwOyAgLy8gU291cmNlIG5vZGUgaGFzIGxldmVsIDAKICAgICAgICAKICAgICAgICB3aGlsZSAoIXEuZW1wdHkoKSkgewogICAgICAgICAgICBpbnQgdiA9IHEuZnJvbnQoKTsKICAgICAgICAgICAgcS5wb3AoKTsKICAgICAgICAgICAgZm9yIChhdXRvIHggOiBHW3ZdKSB7CiAgICAgICAgICAgICAgICBpZiAodXNlZFt4XSA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHgpOwogICAgICAgICAgICAgICAgICAgIHVzZWRbeF0gPSAxOwogICAgICAgICAgICAgICAgICAgIGx2bFt4XSA9IGx2bFt2XSArIDE7ICAvLyBEaXN0YW5jZSBmcm9tIHNvdXJjZQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIAogICAgICAgIC8vIFByaW50IHRoZSBhbnN3ZXJzIGZvciBlYWNoIG5vZGUgKDEgdG8gbikKICAgICAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICAgICAgaWYgKHVzZWRbaV0gPT0gMCkgewogICAgICAgICAgICAgICAgY291dCA8PCAiTm8gIjsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGNvdXQgPDwgIlllcyAiOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgIlxuIjsgIC8vIE5ld2xpbmUgYWZ0ZXIgZWFjaCB0ZXN0IGNhc2UKICAgIH0KICAgIAogICAgcmV0dXJuIDA7Cn0K