#include <bits/stdc++.h>

#define vec vector
#define forn(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
#define YY second
#define XX first
#define vec vector
#define pb push_back
#define ll long long
#define all(a) a.begin(), a.end()

using namespace std;

const bool is_testing = false;

int n, m, p;
vec < pair<int, int> > a;
vec < pair< pair<int, int>, int > > b;

int main()
{
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    if (is_testing)
    {
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    }
    cin >> n >> m >> p;
    a.resize(n);
    b.resize(m);
    forn(i, n)
        cin >> a[i].XX >> a[i].YY;
    forn(i, m)
        cin >> b[i].YY >> b[i].XX.YY >> b[i].XX.XX;
    if (p == 0)
    {
        ll k1 = 0, ans = 0;
        forn(i, n)
            k1 += (ll)a[i].YY;
        sort(all(b));
        reverse(all(b));
        forn(i, m)
        {
            if (k1 >= b[i].XX.YY)
            {
                ans += (ll)b[i].XX.YY * (ll)b[i].XX.XX;
                k1 -= b[i].XX.YY;
            }
            else
            {
                ans += (ll)b[i].XX.XX * (ll)k1;
                k1 = 0;
                break;
            }
        }

        cout << ans;
    }
    else
    {
        cout << "=234235=13=423=4=123=4=3214=2134=21=34=2314";
    }
}
