#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<typename T>
class Mincostflow {
    using TP = pair<T,int>;
    struct edge {
        int to,cap,rev;
        T cost;
        edge(int to,int cap,T cost,int rev):to(to),cap(cap),cost(cost),rev(rev) {}
    };
    T tinf;
    int n;
    vector<vector<edge>> G;
    vector<T> pot,dist;
    vi prevv,preve;
    // potential
    void tinf_init(int x) { tinf = inf; }
    void tinf_init(ll x) { tinf = linf; }

public:
    explicit Mincostflow(int n):n(n),G(n),pot(n),dist(n),prevv(n),preve(n) {
        T x = 0; tinf_init(x);
    }
    void add_edge(int from,int to,T cap,int cost) {
        G[from].eb(to,cap,cost,G[to].size());
        G[to].eb(from,0,-cost,G[from].size()-1);
    }
    // return -1 if impossible
    // this must not be called more than once
    T min_cost_flow(int s,int t,int f) {
        T res = 0;
        pot.assign(n,0);
        while(f > 0) {
            // use dijkstra to update pot
            priority_queue<TP,vector<TP>,greater<TP>> q;
            dist.assign(n,tinf);
            dist[s] = 0;
            q.emplace(0,s);
            while(!q.empty()) {
                T np = q.top().first;
                int v = q.top().second;
                q.pop();
                if(dist[v] < np) continue;
                rep(i,G[v].size()) {
                    edge &e = G[v][i];
                    if(e.cap > 0 && dist[e.to] > dist[v]+e.cost+pot[v]-pot[e.to]) {
                        dist[e.to] = dist[v]+e.cost+pot[v]-pot[e.to];
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        q.emplace(dist[e.to],e.to);
                    }
                }
            }
            if(dist[t] == tinf) return -1;
            rep(i,n) pot[i] += dist[i];

            int d = f;
            for(int v = t; v != s; v = prevv[v]) {
                chmin(d,G[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d*pot[t];
            for(int v = t; v != s; v = prevv[v]) {
                edge &e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    };
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    while(cin >> n,n) {
        vector<tuple<int,int,int,int>> v;
        int ind = 0;
        vector<map<int,int>> in(n),out(n);
        rep(i,n-1) {
            int m;
            cin >> m;
            rep(_,m) {
                int x,y,c;
                cin >> x >> y >> c;
                int nx,ny;
                if(out[i].count(x)) nx = out[i][x];
                else {
                    out[i][x] = ind;
                    nx = ind++;
                }
                if(in[i+1].count(y)) ny = in[i+1][y];
                else {
                    in[i+1][y] = ind;
                    v.eb(ind,ind+1,1,0);
                    ny = ind;
                    ind += 2;
                }
                v.eb(nx,ny,inf,c);
            }
        }
        rep(i,n) {
            for(auto ip : in[i]) {
                for(auto op : out[i]) {
                    if(ip.first <= op.first) {
                        v.eb(ip.second+1,op.second,inf,0);
                    }
                }
            }
        }
        for(auto p : out[0]) v.eb(ind,p.second,inf,0);
        ind++;
        for(auto p : in[n-1]) v.eb(p.second+1,ind,inf,0);
        ind++;
        int g;
        cin >> g;
        for(int i = g; i >= 0; i--) {
            Mincostflow<int> fl(ind);
            for(auto t : v) {
                int a,b,c,d;
                tie(a,b,c,d) = t;
                fl.add_edge(a,b,c,d);
            }
            int d = fl.min_cost_flow(ind-2,ind-1,i);
            if(d != -1) {
                cout << i << " " << d << "\n";
                break;
            }
        }
    }
}



Measured memory_bytes: 3544