#include #include #include #include #include using namespace std; int F[100010]; void Solve() { int n, m, k; cin >> n >> m >> k; for(int i = 1; i <= n; i++) F[i] = n + 1; F[k] = 0; for(int i = 1; i <= m; i++) { int ui, vi; cin >> ui >> vi; if(ui == vi) continue; int a = F[ui], b = F[vi]; F[ui] = min(b, a + 1); F[vi] = min(a, b + 1); } for(int i = 1; i <= n; i++) printf("%d%c", F[i] > n ? -1 : F[i], i == n ? '\n' : ' '); } int main() { int T; cin >> T; while(T--) Solve(); }