#include <bits/stdc++.h>
using namespace std;
priority_queue<int>p;
void solve() {
	while(!p.empty()) p.pop();
    int n, l, m;
    cin >> n >> m >> l;

    vector<pair<int, int>> h(n);
    for (int i = 0; i < n; i++) {
    	int x,y;
        cin >> x >> y;
        h[i] = {x, y - x + 2};
    }
int x[m],u[m];
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> u[i];
        }
       
    int curr = 1, ans = 0; 
    for (int i = 0; i < n; i++) {int j=0;
        while (j<m && x[j]<h[i].first) {p.push(u[j]);j++;}
        while(curr<h[i].second){
        	if(p.empty()){cout<<-1<<endl;return;}
        	curr+=p.top();ans++;p.pop();}}
       
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
