#include<bits/stdc++.h>
#define ll long long 
using namespace std;

const int N = 55;

int n,m,q, box[N], tmp[N];
struct node{
	int w, v;
}a[N];
int cmp(node n1, node n2){ return n1.v > n2.v;}

int main(){
	cin >> n >> m >> q;
	for(int i = 1; i <= n; ++ i)	cin >> a[i].w >> a[i].v;
	sort(a + 1, a + 1 + n, cmp);
	for(int i = 1; i <= m; ++ i)	cin >> box[i];
	while(q --){
		int l, r, idx = 0;
		ll ans = 0;
		cin >> l >> r;
		//printf("l = %d r = %d\n", l, r);
		for(int i = 1; i <= m; ++ i){
			if(i >= l && i <= r)	continue;
			tmp[++ idx] = box[i];
		}
		//printf("idx = %d\n", idx);
		sort(tmp + 1, tmp + 1 + idx);
		for(int i = 1; i <= n; ++ i){
			for(int j = 1; j <= idx; ++ j){
				if(tmp[j] >= a[i].w){
					ans += a[i].v;
					tmp[j] = 0;
					break;
				}
			}
		}
		cout << ans << endl;
	}	
	return 0;
} 	
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/

ll inf = 1e18;
ll p = 998244353 ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,  y, x,  z, g, key,   h, n, m, t, a, b, c, j, k, d;
    ll t2, t3, t4, t1, t5, t6;
    string s, s2;
    ll l, r;
    //cin >> t;
    t = 1;
    ll x1, y1, x2, y2;
    while (t--)
    {
        cin >> n >> m;
        char arr[n][m];
        ll ti, tj;
        vector<set<pll>>adj(26);
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < m; j++)
            {
                cin >> arr[i][j];
                if (arr[i][j] == 'S')
                {
                    ti = i;
                    tj = j;
                }
                if (arr[i][j] >= 'a' && arr[i][j] <= 'z')
                {
                    t1 = arr[i][j] - 'a';
                    adj[t1].insert(mp(i, j));
                }

            }
        }
        ll d[n][m], used[n][m];
        ll ans = -1;
        memset(d, 0, sizeof(d));
        memset(used, 0, sizeof(used));
        queue<pll>q;
        q.push(mp(ti, tj));
        used[ti][tj] = 1;
        d[ti][tj] = 0;

        while (!q.empty())
        {
            auto u = q.front();
            q.pop();
            if (arr[u.fi][u.se] == 'G')
            {
                ans = d[u.fi][u.se];
                break;
            }

            ll dx[4] = {1, -1, 0, 0};
            ll dy[4] = {0, 0, 1, -1};
            for (i = 0; i < 4; i++)
            {
                ll ti = u.fi + dx[i];
                ll tj = u.se + dy[i];
                if (ti >= 0 && ti < n && tj >= 0 && tj < m)
                {
                    if (arr[ti][tj] != '#' && used[ti][tj] == 0)
                    {
                        if (used[ti][tj] == 0)
                        {
                            used[ti][tj] = 1;

                            d[ti][tj] = d[u.fi][u.se] + 1;
                            q.push(mp(ti, tj));

                        }


                    }

                }
            }
            if (arr[u.fi][u.se] >= 'a' && arr[u.fi][u.se] <= 'z')
            {
                t1 = arr[u.fi][u.se] - 'a';
                for (auto v : adj[t1])
                {
                    if (used[v.fi][v.se] == 0)
                    {
                        ti = v.fi;
                        tj = v.se;
                        used[ti][tj] = 1;

                        d[ti][tj] = d[u.fi][u.se] + 1;
                        q.push(mp(ti, tj));

                    }
                }
                adj[t1].clear();
            }
        }
        cout << ans;
    }







    return 0;
}

