# Arup Guha
# 4/3/2026
# Solution to COP 4516 Problem: Come Rain or Shine

def bellmanford(edgeList, source, numV):

    # Default distances.
    dist = [100000000000000]*numV
    dist[source] = 0

    # Number of times to relax all edges.
    for i in range(numV-1):

        for edge in edgeList:

            # Just for readability
            u = edge[0]
            v = edge[1]
            w = edge[2]

            # Relax this edge
            if dist[u] + w < dist[v]:
                dist[v] = dist[u] + w

    return dist

def main():

    nC = int(input())

    for loop in range(nC):

        # Get graph size.
        toks = input().split()
        nV = int(toks[0])
        nE = int(toks[1])

        # Make graph and one with negative edges.
        regG = []
        negG = []

        # Add edges.
        for i in range(nE):

            # Original graph.
            vals = [int(x) for x in input().split()]
            regG.append(vals)

            # Negative graph.
            other = [vals[0], vals[1], -vals[2]]
            negG.append(other)

        # Run both shortest distance algorithms and output the results
        # Flip negative answer...
        d1 = bellmanford(regG, 0, nV)
        d2 = bellmanford(negG, 0, nV)
        print(d1[nV-1],-d2[nV-1])

main()
