#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight capacity, cost;
  int rev;
  Edge(int src, int dst, Weight capacity, Weight cost) :
    src(src), dst(dst), capacity(capacity), cost(cost) { }
  Edge(int src, int dst, Weight capacity, Weight cost, int rev) :
    src(src), dst(dst), capacity(capacity), cost(cost), rev(rev) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.cost != f.cost ? e.cost > f.cost : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int s, int d, Weight cap, Weight cost) {
  g[s].push_back(Edge(s,d,cap,cost,g[d].size()));
  g[d].push_back(Edge(d,s,0,-cost,g[s].size()-1));
}

pair<Weight, Weight> minimumCostFlow4(Graph g, int s, int t) {
  const int n = g.size();
  pair<Weight, Weight> total; // (cost, flow)
  
  vector<Weight> h(n,INF);
  h[s] = 0;
  REP(k, n) {
    bool update = 0;
    REP(i, n) {
      FOR(e,g[i]) if (e->capacity)
        if (h[e->dst] > h[e->src] + e->cost) {
          h[e->dst] = h[e->src] + e->cost;
          update = 1;
        }
    }
    if (!update) break;
  }
  
  for (int F = INF; F > 0;) { // residual flow
    vector<Weight> d(n, INF); d[s] = 0;
    vector<int> pv(n,-1), pe(n);
    priority_queue<Edge> Q;
    for (Q.push(Edge(-2,s,0,0)); !Q.empty(); ) {
      Edge e = Q.top(); Q.pop();
      if (pv[e.dst] != -1) continue;
      pv[e.dst] = e.src;
      pe[e.dst] = e.rev;
      REP(i, g[e.dst].size()) {
        Edge &f = g[e.dst][i];
        if (f.capacity > 0 && d[f.dst] > d[f.src] + f.cost + h[f.src] - h[f.dst]) {
          d[f.dst] = d[f.src] + f.cost + h[f.src] - h[f.dst];
          Q.push(Edge(f.src, f.dst, 0, d[f.dst], i));
        }
      }
    }
    if (pv[t] == -1) break;
    Weight f = F;
    for (int u = t; u != s; u = pv[u])
      f = min(f, g[pv[u]][pe[u]].capacity);
    if (!f) break;
    for (int u = t; u != s; u = pv[u]) {
      total.first += f * g[pv[u]][pe[u]].cost;
      g[pv[u]][pe[u]].capacity -= f;
      g[u][g[pv[u]][pe[u]].rev].capacity += f;
    }
    F -= f;
    total.second += f;
    REP(u,n) if (h[u] != INF) h[u] += d[u];
  }
  return total;
}

int m[100];
int a[100][20];
int b[100][20];
int c[100][20];
map<int,int> mp[100];

int num[101];
int cnt;
int n;

int SOURCE2() { return num[n-1] + cnt*2+2; }
int SOURCE() { return num[n-1] + cnt*2; }
int SINK() { return num[n-1] + cnt*2+1; }
int NODE(int i, int j) { return num[i] + j; }
int IN(int k) { return num[n-1] + k*2; }
int OUT(int k) { return num[n-1] + k*2 + 1; }

int main() {
  while(cin>>n,n) {
    cnt = 0;
    num[0] = 0;
    REP(i,n-1)mp[i].clear();
    REP(i,n-1) {
      cin >> m[i];
      num[i+1] = num[i] + m[i];
      REP(j,m[i]) {
        cin >> a[i][j] >> b[i][j] >> c[i][j];
        if (mp[i].count(b[i][j]) == 0) mp[i][b[i][j]] = cnt++;
      }
    }
    int group; cin >> group;
    Graph g(num[n-1]+2*cnt+3);
    
    REP(i,n-1) {
      REP(j,m[i]) {
        add_edge(g, NODE(i,j), IN(mp[i][b[i][j]]), 1, c[i][j]);
      }
      FOR(it, mp[i]) {
        add_edge(g, IN(it->second), OUT(it->second), 1, 0);
      }
      if (i) {
        FOR(it, mp[i-1]) {
          REP(j,m[i]) {
            if (it->first <= a[i][j]) {
              add_edge(g, OUT(it->second), NODE(i,j), 1, 0);
            }
          }
        }
      }
    }
    REP(i,m[0]) {
      add_edge(g, SOURCE2(), NODE(0,i), 1, 0);
    }
    add_edge(g, SOURCE(), SOURCE2(), group, 0);
    FOR(it, mp[n-2]) {
      add_edge(g, OUT(it->second), SINK(), 1, 0);
    }
    pii ans = minimumCostFlow4(g,SOURCE(),SINK());
    cout << ans.second << " " << ans.first << endl;
  }
}

Measured memory_bytes: 6336