#include <bits/stdc++.h>
using namespace std;
const int MAX = 5005;
vector<int> va(MAX), vb(MAX), vc(MAX);
vector<int> edges[MAX];
vector<int> imp[MAX];
int mmax;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, k, a, b;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) cin >> va[i] >> vb[i] >> vc[i];
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    sort(edges[i].begin(), edges[i].end());
    int last;
    if (edges[i].size() == 0)
      last = i;
    else
      last = max(i, edges[i].back());
    imp[last].push_back(vc[i]);
  }
  for (int i = 1; i <= n; i++) {
    sort(imp[i].begin(), imp[i].end());
  }
  multiset<int> st;
  int sol = 0;
  for (int i = 1; i <= n; i++) {
    while (k < va[i] && !st.empty()) {
      k++;
      st.erase(st.begin());
    }
    if (k < va[i]) {
      cout << -1 << "\n";
      return 0;
    }
    k += vb[i];
    if (imp[i].size() == 0) continue;
    while (k > 0 && imp[i].size() > 0) {
      k--;
      st.insert(imp[i].back());
      imp[i].pop_back();
    }
    while (imp[i].size() > 0 && st.size() > 0 && imp[i].back() > *st.begin()) {
      st.erase(st.begin());
      st.insert(imp[i].back());
      imp[i].pop_back();
    }
  }
  while (!st.empty()) {
    sol += *st.begin();
    st.erase(st.begin());
  }
  cout << sol << "\n";
  return 0;
}
