#include using namespace std; const int MAXN = 100005; const int MAX = 1e9; int dp[MAXN]; int main() { int T, n, m,k; cin>>T; while(T--) { for(int j=0;j>n>>m>>k; dp[k] = 0; for(int i=1;i<=m;i++) { int a, b; scanf("%d %d", &a, &b); int dp_a = min(dp[a] + 1, dp[b]); int dp_b = min(dp[b] + 1, dp[a]); dp[a] = dp_a; dp[b] = dp_b; } for (int i = 1; i<=n;i++) { if (i > 1) printf(" "); if(dp[i] >= MAX) printf("%d", -1); else printf("%d", dp[i]); } printf("\n"); } return 0; }