/* AOJ 1088 : School Excursion */
/*
	Graph,
	Flow, Minimum Cost Flow,
	Implementation
*/

// ¸_É¬Ê§Àª éÅ¬ïp¬
// OtÌ\zª©ÈèåÏ

#include<map>
#include<queue>
#include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int V_MAX=6000;
const int CAPA_INF=1<<29;
const int COST_INF=1<<29;

template<class T,class U>
struct edge{
	int v,rev;
	T capa;
	U cost;
	T flow;
};

template<class T,class U>
void add_directed_edge(vector< edge<T,U> > *G,int u,int v,T capa,U cost){
	G[u].push_back((edge<T,U>){v,G[v].size()  ,capa, cost,0});
	G[v].push_back((edge<T,U>){u,G[u].size()-1,   0,-cost,0});
}

template<class T,class U>
pair<T,U> augment(int n,vector< edge<T,U> > *G,int s,int t,U *pot){
	static int pre[V_MAX];
	static U d[V_MAX];
	rep(u,n) d[u]=(u==s?0:COST_INF);

	// Dijkstra
	bool ok=false;
	priority_queue< pair<U,int> > Q; Q.push(make_pair(0,s));
	while(!Q.empty()){
		int u=Q.top().second;
		U cost=-Q.top().first; Q.pop();

		if(cost<d[u]) continue;
		if(u==t) ok=true;

		rep(i,G[u].size()){
			edge<T,U> &e=G[u][i];
			U cost2=cost+e.cost+pot[u]-pot[e.v];
			if(e.capa-e.flow>0 && cost2<d[e.v]){
				d[e.v]=cost2;
				pre[e.v]=e.rev;
				Q.push(make_pair(-cost2,e.v));
			}
		}
	}

	if(!ok) return make_pair(0,0);

	T water=CAPA_INF;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		water=min(water,e2.capa-e2.flow);
		v=e1.v;
	}

	U cost=0;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		e1.flow-=water;
		e2.flow+=water;
		cost+=water*e2.cost;
		v=e1.v;
	}

	rep(u,n) pot[u]+=d[u];

	return make_pair(water,cost);
}

template<class T,class U>
pair<T,U> primal_dual(int n,vector< edge<T,U> > *G,int s,int t){
	T ans1=0;
	U ans2=0;
	static U pot[V_MAX];
	while(1){
		pair<T,U> tmp=augment(n,G,s,t,pot);
		if(tmp.first==0) break;
		ans1+=tmp.first;
		ans2+=tmp.second;
	}
	return make_pair(ans1,ans2);
}

struct train{
	int t1,t2,cost; // o­, , ^À
};

struct node{
	int id,t,type; // wÌÔ, (o­ or ), type==0?ÓÂ¤Ì¸_:ªô³¹½¸_

	// \[gµ½Æ«ÉAw 1 ÌêÔ¢CxgªÅAw n ÌêÔx¢CxgªÅãÉéæ¤È
	bool operator<(const node &u)const{
		if(id!=u.id) return id<u.id;
		if(t!=u.t) return t<u.t;
		return type>u.type;
	}
};

int main(){
	for(int n;scanf("%d",&n),n;){
		vector<train> T[99];
		rep(i,n-1){
			int m; scanf("%d",&m);
			T[i].resize(m);
			rep(j,m) scanf("%d%d%d",&T[i][j].t1,&T[i][j].t2,&T[i][j].cost);
		}
		int n_class; scanf("%d",&n_class);

		map<node,int> f; // ¸_ -> ¸_Ô
		map<node,int> g; // ¸_ u -> u ðªô³¹½¸_ÌÔ ( u ÉüÁÄ­éÓªoR·é )
		rep(i,n-1){
			int m=T[i].size();
			rep(j,m){
				f[(node){ i ,T[i][j].t1,0}];
				f[(node){i+1,T[i][j].t2,0}];
				g[(node){i+1,T[i][j].t2,1}];
			}
		}

		map<node,int> h; // h := f cup g
		map<node,int>::iterator it;
		h.insert(f.begin(),f.end());
		h.insert(g.begin(),g.end());

		int n_graph=0;
		for(it=h.begin();it!=h.end();++it) it->second=n_graph++;

		// map::iterator Ì ++ ð½xàsíÈ¢½ßÌ¬×H
		static node a[V_MAX];
		for(it=h.begin();it!=h.end();++it) a[it->second]=it->first;

		int s=n_graph,t=s+1;
		n_graph+=2;
		vector< edge<int,int> > G[V_MAX];

		// build graph
		// ÁêÈÓ ( source, sink )
		add_directed_edge(G,s,0,n_class,0);
		add_directed_edge(G,s-1,t,n_class,0);
		// ÁêÈÓ ( dÔÒ¿ )
		rep(j,n_graph-2) rep(i,j) {
			node u=a[i],v=a[j];
			if(u.id==v.id && u.type==0 && v.type==0){
				add_directed_edge(G,i,j,n_class,0);
			}
		}
		// ÁêÈÓ ( ªô³¹½¸_Ô )
		rep(i,n_graph-2){
			node u=a[i];
			if(u.type==1){ // ªô³¹½¸_ÉÂ¢Ä
				u.type=0;
				add_directed_edge(G,i,h[u],1,0);
			}
		}
		// ÊíÌÓ ( dÔÉ )
		rep(i,n-1){
			int m=T[i].size();
			rep(j,m){
				node u={ i ,T[i][j].t1,0};
				node v={i+1,T[i][j].t2,1};
				add_directed_edge(G,h[u],h[v],1,T[i][j].cost);
			}
		}

		pair<int,int> ans=primal_dual(n_graph,G,s,t);
		printf("%d %d\n",ans.first,ans.second);
	}

	return 0;
}

Measured memory_bytes: 2900