#include using namespace std; #define rep(i,a,n) for (int i=a;i=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector VI; typedef long long ll; typedef pair PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N = 100010; int f[N]; int main() { int T; scanf("%d", &T); while(T--) { int n, m, k; scanf("%d%d%d", &n, &m, &k); for(int i=1; i<=n; i++) f[i] = -1; f[k] = 0; while(m--) { int u, v; scanf("%d%d", &u, &v); if(f[u]<0 && f[v]<0) continue; int x = f[u], y = f[v]; if(f[v]>=0 && (f[u]<0 || f[v]<=f[u])) x = f[v]; else x++; if(f[u]>=0 && (f[v]<0 || f[u]<=f[v])) y = f[u]; else y++; f[u] = x; f[v] = y; } for(int i=1; i<=n; i++) { printf("%d", f[i]); if(i