#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std;

class Edge{
public:
    int to, cap, cost, rev;
    Edge(){};
    Edge(int to0, int cap0, int cost0){to = to0; cap = cap0, cost = cost0;}
    Edge(int to0, int cap0, int cost0, int rev0){to = to0; cap = cap0; cost = cost0; rev = rev0;}
};

int minCostFlow(const vector<vector<Edge> >& edges0, int source, int sink, int flow)
{
    int n = edges0.size();
    vector<vector<Edge> > edges(n);
    for(int i=0; i<n; ++i){
        for(unsigned j=0; j<edges0[i].size(); ++j){
            const Edge& e = edges0[i][j];
            edges[i].push_back(Edge(e.to, e.cap, e.cost, edges[e.to].size()));
            edges[e.to].push_back(Edge(i, 0, -e.cost, edges[i].size()-1));
        }
    }

    vector<int> h(n, 0);
    vector<int> prevV(n);
    vector<int> prevE(n);

    int ret = 0;
    while(flow > 0){
        vector<int> dist(n, INT_MAX);
        dist[source] = 0;
        priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
        q.push(make_pair(0, source));

        while(!q.empty()){
            pair<int, int> p = q.top();
            q.pop();
            int v = p.second;
            if(dist[v] < p.first)
                continue;
            for(unsigned i=0; i<edges[v].size(); ++i){
                Edge e = edges[v][i];
                if(e.cap > 0 && dist[v] + e.cost + h[v] - h[e.to] < dist[e.to]){
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevV[e.to] = v;
                    prevE[e.to] = i;
                    q.push(make_pair(dist[e.to], e.to));
                }
            }
        }
        if(dist[sink] == INT_MAX){
            return -1;
        }
        for(int i=0; i<n; ++i)
            h[i] += dist[i];

        int g = flow;
        for(int i=sink; i!=source; i=prevV[i])
            g = min(g, edges[prevV[i]][prevE[i]].cap);
        for(int i=sink; i!=source; i=prevV[i]){
            Edge& e = edges[prevV[i]][prevE[i]];
            e.cap -= g;
            edges[i][e.rev].cap += g;
        }
        flow -= g;
        ret += g * h[sink];
    }
    return ret;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> m(n);
        vector<vector<int> > x(n), y(n), c(n);
        for(int i=0; i<n-1; ++i){
            cin >> m[i];
            x[i].resize(m[i]);
            y[i].resize(m[i]);
            c[i].resize(m[i]);
            for(int j=0; j<m[i]; ++j)
                cin >> x[i][j] >> y[i][j] >> c[i][j];
        }
        m[n-1] = 1;
        x[n-1].push_back(INT_MAX);
        y[n-1].push_back(INT_MAX);
        c[n-1].push_back(0);

        vector<vector<Edge> > edges(1);
        map<int, int> index;
        index[0] = 0;
        for(int i=0; i<n; ++i){
            for(int j=0; j<m[i]; ++j){
                int t = edges.size();
                edges.push_back(vector<Edge>());
                for(map<int, int>::iterator it=index.begin(); it!=index.end(); ++it){
                    if(it->first <= x[i][j])
                        edges[it->second].push_back(Edge(t, 1, 0));
                }
            }

            index.clear();
            int s = edges.size() - m[i];
            for(int j=0; j<m[i]; ++j){
                if(index.find(y[i][j]) == index.end()){
                    index[y[i][j]] = edges.size();
                    edges.push_back(vector<Edge>());
                }
                int t = index[y[i][j]];
                edges[s].push_back(Edge(t, 1, c[i][j]));
                ++ s;
            }

            for(map<int, int>::iterator it=index.begin(); it!=index.end(); ++it){
                int s = it->second;
                int t = edges.size();
                edges.push_back(vector<Edge>());
                edges[s].push_back(Edge(t, 1, 0));
                it->second = t;
            }
        }

        int g;
        cin >> g;
        for(;;){
            int ret = minCostFlow(edges, 0, edges.size()-3, g);
            if(ret != -1){
                cout << g << ' ' << ret << endl;
                break;
            }
            -- g;
        }
    }
}

Measured memory_bytes: 4128