There are N (labelled 1 to N) kingdoms in a country. Our king Alexander is living in the kingdom S. We are given R distances, these distances are between two kingdoms and the distance between any two kingdom may or may not be unique.

Now Alexander wants to visit each kingdom in minimum distance possible starting from his kingdom S.

If a kingdom is unreachable the distance is assumed as -1.

INPUT:::

The first line denotes T, the number of test cases.

First line of each test case has two integers, denoting the no of kingdom "N" and the next number denotes the no of distance given between two different kingdoms "R".

The next "R" line contains three integers x,y,d, the first two numbers denoting kingdom number and the next integer denotes the distance between them.

If the distance between two kingdom say a and b is given as x then this distance will remain same if the Alexander travels from a to b or from b to a.

The last line of test case denotes the kingdom in which Alexander is living.

Note::: If there are many distances given between the same two kingdoms then it is considered that Alexander has many different ways to travel between these two kingdoms.

Output:::

For each test case print a single line containing N-1 space separated integers denoting the shortest distance of N-1 kingdoms from Alexander's Kingdom.

For unreachable kingdoms print "-1".

Constraints:::
1≤T≤10,
2≤N≤3000, 
1≤R≤N×(N−1))2,
1≤x,y,S≤N,
1≤d≤350

SAMPLE INPUT
1
4 4
1 2 24
1 4 20
3 1 3
4 3 12
1

SAMPLE OUTPUT
24 3 15
def killdoubles(l):
    i=0
    a=l[i]
    ll=[a]
    while i<len(l):
        if a!=l[i]:
            a=l[i]
            ll.append(a)
        i+=1
    return ll

def argminnonmarque(l,m):
    mini=min([l[i] for i in range(len(l)) if not(m[i])])
    for i in range(len(l)):
        if ((l[i]==mini) & (not(m[i]))):
            break
    return i
def subs(a,l):
    i=0
    dont=False
    while i<len(l):
        if l[i][0]==a[0]:
            if l[i][1]>a[1]:
                break
            dont=True
        i+=1
    ll=[list(k) for k in l]
    if i<len(l):
        ll[i]=a
    elif not(dont):
        ll.append(a)
    return ll
def solve(n,m,r,s):
    G=[[] for _ in range(n+1)]
    for [i,j,w] in r:
        G[i]=subs([j,w],G[i])
        G[j]=subs([i,w],G[j])
        
    infinity=1+sum([r[i][2] for i in range(m)])
    
    for debut in [s]:
        marque=[False for _ in range(n+1)]
        labels=[infinity for _ in range(n+1)]
        labels[debut]=0
        while marque!=[True for _ in range(n+1)]:
            a=argminnonmarque(labels,marque)
            marque[a]=True
            for [b,w] in G[a]:
                if not(marque[b]):
                    labels[b]=min(labels[b],labels[a]+w)
        for i in range(n+1):
            if labels[i]==infinity:
                labels[i]=-1
    st=""
    for i in (labels[1:s]+labels[s+1:]):
        st+=str(i)+" "
    return st


T=int(raw_input())
for _ in range(T):
    [n,m]=map(int,raw_input().strip().split())
    r=[]
    for _ in range(m):
        r.append(map(int,raw_input().strip().split()))
    s=int(raw_input())
    print(solve(n,m,r,s))