// AUTHOR:- Saumya Rangani

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector<pair<int,int>>
#define fr first
#define sc second
#define all(c) c.begin(), c.end()
#define it(a) for(auto &i:a)
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define read(v) for(auto &i:v)cin>>i;
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define in cin>>
#define out cout<<
#define default(a,n,b) for(int i=0;i<n;i++)a[i]=b;
#define YNans(poss) cout << (poss ? "YES" : "NO" ) << endl;
#define inarray(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define fast ios_base :: sync_with_stdio(false),cin.tie(NULL);
#define MAXN 2005


int gcd(int a, int b){return (b?gcd(b,a%b):a);}
bool isPrime(int n){if(n==1) return false;if(n==2) return true;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
int power(long long x, unsigned int y, int p=mod){int res = 1;x = x % p; if (x == 0) return 0;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int digit(int n){int ans=0;while(n){ans++;n/=10;}return ans;}
int lcm(int a,int b){return a*b/gcd(a,b);}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}

vector<vector<int>> grp(MAXN);
bool vis[MAXN];
int  dfs(int node){
    int ans=1;
    if(vis[node]){
        return 0;
    }
    vis[node]=1;
    // cout<<node<<endl;
    for(auto i:grp[node]){
        ans+=dfs(i);
    }
    return ans;
}

void solve(){
    int n;in n;
    int m;in m;
    for(int i=0;i<m;i++){
        int x,y;in x>>y;
        grp[x].pb(y);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        ans+=dfs(i);
    }
    cout<<ans<<endl;
}

int32_t main(){
    fast
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <algorithm>
#include <iostream>
#include <array>
using namespace std;
#define f(x,y,z) for(int x=y;x<=z;++x)
int n, m, q, l, r, h, mn, imn;
array<int, 51> bx, kt;
pair<int, int> bg[51];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m >> q;
    f(i,1,n) cin >> bg[i].second >> bg[i].first;
    sort(bg+1, bg+n+1, greater<pair<int, int>>());
    f(i,1,m) cin >> kt[i];
    while(q--) {
        cin >> l >> r;
        h = 0, bx = kt;
        f(i,1,n) {
            imn = 0, mn = 1e9;
            f(j,1,m) if(j < l || j > r) {
                if(bx[j] >= bg[i].second && bx[j] < mn) {
                    mn = bx[j], imn = j;
                }
            }
            if(imn) h += bg[i].first, bx[imn] = 0;
        }
        cout << h << '\n';
    }
}