#include
#include
using namespace std;
class Graph
{
public:
int v;
list*l;
Graph(int n)
{
v=n;
l=new list[v];
}
void addEdge(int a,int b)
{
l[a].push_back(b);
l[b].push_back(a);
}
};
int main() {
int q;
cin>>q;
while(q–)
{
int n,m;
cin>>n>>m;
Graph g(n);
while(m–)
{
int a,b;
cin>>a>>b;
g.addEdge(a,b);
}
int src;
cin>>src;
for(int i=1;i<=n;i++)
{ int flag=0;
for(auto vertex:g.l[src])
{ flag=0;
if(i==vertex)
{
cout<<"6 ";
flag=1;
break;
}
}
if(flag==0)
{
cout<<"-1 ";
}
}
cout<<endl;
}
return 0;
}