#include <bits/stdc++.h>
#ifdef LILY
#include "./Debug.h"
#else
#define var(...) (0)
#define dbg(...) (0)
#endif
using int32 = int;
using int64 = long long;
using namespace std;

class Solution
{
#define int int64
#define sfor(i, n) for (int i = 1; i <= (n); ++i)
#define tfor(i, n) for (int i = 0; i < (n); ++i)

    int n, m, l, r, res;
    vector<int> x;
    using p = pair<int, int>;
    vector<p> t;

    void SHURU()
    {
        cin >> l >> r;
        --l, --r;
        res = 0;
    }

    void SHUCHU()
    {
        cout << res << endl;
    }

    void CHULI()
    {
        vector<int> cases;
        for (int i = 0; i < m; ++i)
        {
            if (i < l || i > r)
                cases.push_back(x[i]);
        }
        if (cases.size() == 0) return;
        sort(cases.begin(), cases.end());
        for (auto i : t)
        {
            auto j = lower_bound(cases.begin(), cases.end(), i.first);
            if (j == cases.end()) continue;
            cases.erase(j);
            res += i.second;
            if (cases.size() == 0) return;
        }
    }

public:
    Solution()
    {
        int q, s, y;
        cin >> n >> m >> q;
        tfor(i, n)
        {
            cin >> s >> y;
            t.emplace_back(s, y);
        }
        tfor(i, m)
        {
            cin >> s;
            x.push_back(s);
        }
        sort(t.begin(), t.end(), [](p a, p b) {
            return a.second > b.second;
        });
        while (q--)
        {
            SHURU();
            CHULI();
            SHUCHU();
        }
    }
#undef int
#undef tfor
#undef sfor
};

int32 main()
#ifndef LILY
{
    Solution();
}
#endif


// Problem: B - Reversible Cards
// Contest: AtCoder - AtCoder Regular Contest 111
// URL: https://atcoder.jp/contests/arc111/tasks/arc111_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

struct splitmix64_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}
 
	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
 
template <typename K, typename V, typename Hash = splitmix64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;
 
template <typename K, typename Hash = splitmix64_hash>
using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

bool cycle, has[maxN], visited[maxN];
vi graph[maxN];

int DFS(int x, int prv) {
	int ile = 1;
	visited[x] = true;
	for (auto v: graph[x]) {
		// cout << x << " " << prv << ": " << v << endl;
		if (!visited[v]) {
			ile += DFS(v, x);
		} else {
			if (v != prv) {
				cycle = true;
			}
		}
	}
	return ile;
}

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	int mx = 0;
	REP(i, n) {
		int a, b; cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
		mx = max(mx, max(a, b));
		has[a] = true;
		has[b] = true;
	}
	int ans = 0;
	RI(i, mx) {
		if (!has[i]) continue;
		if (!visited[i]) {
			int ile = DFS(i, -1);
			// cout << ile << " " << cycle << endl;
			ans += ile - !cycle;
			cycle = false;
		}
	}
	cout << ans;
	return 0;
}
 
