#include <bits/stdc++.h>
using namespace std;
long n, k, t, h, w, r;
unsigned short be[30];
unsigned short bew[30];
unsigned long long z = 0;
class marry {
 public:
  int m;
  int w;
  int r;
  marry(int m1, int w1, int r1) {
    m = m1;
    w = w1;
    r = r1;
  }
  bool operator<(const marry* mm) { return r < mm->r; }
};
bool cmp(marry* m1, marry* m2) { return m1->r < m2->r; }
vector<marry*> a;
int main() {
  cin >> n >> k >> t;
  for (int i = 1; i <= k; i++) {
    cin >> h >> w >> r;
    a.push_back(new marry(h, w, r));
  }
  sort(a.begin(), a.end(), &cmp);
  long j = 0;
  long p = 0;
  do {
    long d = j++;
    bool f = true;
    z = 0;
    memset(be, 0, sizeof(be));
    memset(bew, 0, sizeof(bew));
    for (long i = 0; i < a.size(); i++) {
      long tt = d % 2;
      d /= 2;
      if (tt) {
        z += a[i]->r;
        if (be[a[i]->m] || bew[a[i]->w]) {
          f = false;
          break;
        }
        be[a[i]->m] = 1;
        bew[a[i]->w] = 1;
      }
    }
    if (f) {
      ++p;
      cout << j - 1 << ' ' << z << endl;
    }
  } while (p < t);
  cout << z;
  return 0;
}
