#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXN = 51000;
unsigned long long x[MAXN], y[MAXN], a[MAXN], b, c;
unsigned long long suma = 0;

vector <pair <long long, long long> > d;

int main() {
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	int n, m, p;
	cin >> n >> m >> p;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x[i], &a[i]);
		suma += a[i];
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &y[i], &b, &c);
		d.push_back(make_pair(-c, b));
	}
	
	if (p == 0) {
		sort(d.begin(), d.end());
		int ind = 0;
		unsigned long long ans = 0;
		while (suma != 0 && ind < m) {
			if (d[ind].second <= suma) {
				ans += d[ind].second * (-d[ind].first);
				suma -= d[ind].second;
			}
			else {
				ans += suma * (-d[ind].first);
				suma = 0;
			}
			ind++;
		}
		cout << ans;
	}
	return 0;
}
/*
3 4 0
SSSS
EESW
ENWW

4 4 0
esSS
nwSS
nNES
NNNW

1 5 0

*/