# ZOJ - 3946 最短路+贪心

/**/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=110000+100;
struct node
{
int distance,point,val;
node(){}
node(int _point,int _distance,int _val)
{
point=_point;
distance=_distance;
val=_val;
}
friend bool operator <(node aa,node bb)
{
if(aa.distance==bb.distance)
return aa.val>bb.val;
return aa.distance>bb.distance;
}
};
struct edge
{
int v,w,val,nxt;
}edge[maxn*4+100];
void add_edge(int u,int v,int w,int val)
{
edge[cnt].v=v;
edge[cnt].w=w;
edge[cnt].val=val;
}
long long dis[maxn],value[maxn];
int vis[maxn];
int n,m;
void zyz(int s)
{
for(int i=0;i<=n;i++)
{
dis[i]=((long long )1) << 61;
value[i]=((long long)1) << 61;
}
dis[s]=0;
value[s]=0;
memset(vis,0,sizeof(vis));
priority_queue<node>q;
q.push(node(s,dis[s],value[s]));
while(!q.empty())
{
node now;
now=q.top();
q.pop();
if(vis[now.point])
continue;
vis[now.point]=1;
{
int v=edge[i].v;
if(vis[v]==0)
{
if(dis[v]>dis[now.point]+edge[i].w)
{
dis[v]=dis[now.point]+edge[i].w;
value[v]=edge[i].val;
q.push(node(v,dis[v],value[v]));
}
if(dis[v]==dis[now.point]+edge[i].w)
{
if(value[v]>edge[i].val)
{
value[v]=edge[i].val;
q.push(node(v,dis[v],value[v]));
}
}
}
}
}
}
int main ()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
cnt=0;
for(int i=1;i<=m;i++)
{
int xx,yy,zz,xy;
scanf("%d%d%d%d",&xx,&yy,&zz,&xy);
}
zyz(0);
long long sum=0;
for(int i=1;i<n;i++)
{
sum+=dis[i];
//printf("i:%d %d\n",i,dis[i]);
}
printf("%lld ",sum);
sum=0;
for(int i=1;i<n;i++)
{
//  if(value[i]!=0x3f3f3f3f)
{
sum+=value[i];
}
}
printf("%lld\n",sum);
}
}